API
OrionAuth.GenericRequestContext — TypeGenericRequestContext <: RequestContextGeneric implementation of RequestContext for testing and direct use.
Fields
headers::Dict{String,String}: HTTP request headers
Examples
ctx = GenericRequestContext(Dict("Authorization" => "Bearer token123"))
token = extract_bearer_token(ctx)OrionAuth.HTTPRequestContext — TypeHTTPRequestContext <: RequestContextAdapter for HTTP.jl requests.
Examples
using HTTP
# In an HTTP.jl handler:
HTTP.serve() do req
ctx = HTTPRequestContext(req)
try
payload = Auth(ctx)
return HTTP.Response(200, "Success")
catch ex
if ex isa ResponseException
return to_http_response(ex)
end
rethrow()
end
endOrionAuth.OxygenRequestContext — TypeOxygenRequestContext <: RequestContextAdapter for Oxygen framework requests.
Examples
using Oxygen
# In an Oxygen route handler:
@get "/protected" function(req)
ctx = OxygenRequestContext(req)
payload = Auth(ctx)
# ... handle request
endOrionAuth.RequestContext — TypeRequestContextAbstract type representing an HTTP request context across different frameworks. Implementations should provide access to request headers.
OrionAuth.ResponseException — TypeResponseExceptionException type for HTTP responses with status code, headers, and body. Can be thrown to return an HTTP error response in a framework-agnostic way.
Fields
status::Int: HTTP status code (e.g., 401, 403, 404)headers::Vector{Pair{String,String}}: HTTP response headersbody::String: Response body content
Examples
# Unauthorized response
throw(ResponseException(401, [], "Unauthorized"))
# Forbidden with custom header
throw(ResponseException(403, ["Content-Type" => "application/json"], "Forbidden"))OrionAuth.configure_framework! — Methodconfigure_framework!(framework::Symbol)Configure OrionAuth to use a specific framework adapter.
Arguments
framework::Symbol: Framework to use (:genie,:oxygen,:http, or:auto)
Examples
# Set framework explicitly
configure_framework!(:genie)
# Enable auto-detection (default)
configure_framework!(:auto)OrionAuth.create_request_context — Functioncreate_request_context(request=nothing) -> RequestContextAutomatically create the appropriate RequestContext based on configuration or auto-detection.
Arguments
request: Optional request object (auto-detected if not provided)
Returns
RequestContext: Appropriate context for the configured/detected framework
Examples
# Auto-detect from environment
ctx = create_request_context()
# Explicit request object
ctx = create_request_context(req)OrionAuth.extract_bearer_token — Methodextract_bearer_token(ctx::RequestContext) -> StringExtract JWT token from the Authorization Bearer header.
Arguments
ctx::RequestContext: The request context with headers
Returns
String: The JWT token
Throws
ResponseException(401, ...): If Authorization header is missingResponseException(400, ...): If Authorization header format is invalid
Examples
token = extract_bearer_token(ctx)
# Returns: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."OrionAuth.get_configured_framework — Methodget_configured_framework() -> SymbolGet the currently configured framework.
Returns
- Symbol representing the framework (
:genie,:oxygen,:http, or:auto)
OrionAuth.get_headers — Functionget_headers(ctx::RequestContext) -> Dict{String,String}Extract headers from the request context.
Arguments
ctx::RequestContext: The request context
Returns
Dict{String,String}: Dictionary of HTTP headers
Examples
headers = get_headers(ctx)
auth_header = get(headers, "authorization", nothing)OrionAuth.get_headers — Methodget_headers(ctx::HTTPRequestContext) -> Dict{String,String}Extract headers from HTTP.Request.
Arguments
ctx::HTTPRequestContext: HTTP request context
Returns
Dict{String,String}: Dictionary of HTTP headers
OrionAuth.get_headers — Methodget_headers(ctx::OxygenRequestContext) -> Dict{String,String}Extract headers from Oxygen request context.
Arguments
ctx::OxygenRequestContext: Oxygen request context
Returns
Dict{String,String}: Dictionary of HTTP headers
OrionAuth.handle_auth_exception — Methodhandle_auth_exception(ex::ResponseException) -> AnyConvert ResponseException to the appropriate framework-specific response.
Arguments
ex::ResponseException: The exception to convert
Returns
- Framework-specific error response
Examples
try
Auth()
catch ex
if ex isa ResponseException
return handle_auth_exception(ex)
end
rethrow()
endOrionAuth.to_http_response — Methodto_http_response(ex::ResponseException) -> HTTP.ResponseConvert ResponseException to HTTP.Response.
Arguments
ex::ResponseException: The response exception to convert
Returns
HTTP.Response: HTTP response with status, headers, and body
OrionAuth.to_oxygen_response — Methodto_oxygen_response(ex::ResponseException) -> HTTP.ResponseConvert ResponseException to HTTP.Response for Oxygen.
Arguments
ex::ResponseException: The response exception to convert
Returns
HTTP.Response: HTTP response with status, headers, and body