API

OrionAuth.GenericRequestContextType
GenericRequestContext <: RequestContext

Generic 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)
source
OrionAuth.HTTPRequestContextType
HTTPRequestContext <: RequestContext

Adapter 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
end
source
OrionAuth.OxygenRequestContextType
OxygenRequestContext <: RequestContext

Adapter for Oxygen framework requests.

Examples

using Oxygen

# In an Oxygen route handler:
@get "/protected" function(req)
    ctx = OxygenRequestContext(req)
    payload = Auth(ctx)
    # ... handle request
end
source
OrionAuth.RequestContextType
RequestContext

Abstract type representing an HTTP request context across different frameworks. Implementations should provide access to request headers.

source
OrionAuth.ResponseExceptionType
ResponseException

Exception 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 headers
  • body::String: Response body content

Examples

# Unauthorized response
throw(ResponseException(401, [], "Unauthorized"))

# Forbidden with custom header
throw(ResponseException(403, ["Content-Type" => "application/json"], "Forbidden"))
source
OrionAuth.configure_framework!Method
configure_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)
source
OrionAuth.create_request_contextFunction
create_request_context(request=nothing) -> RequestContext

Automatically 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)
source
OrionAuth.extract_bearer_tokenMethod
extract_bearer_token(ctx::RequestContext) -> String

Extract 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 missing
  • ResponseException(400, ...): If Authorization header format is invalid

Examples

token = extract_bearer_token(ctx)
# Returns: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
source
OrionAuth.get_configured_frameworkMethod
get_configured_framework() -> Symbol

Get the currently configured framework.

Returns

  • Symbol representing the framework (:genie, :oxygen, :http, or :auto)
source
OrionAuth.get_headersFunction
get_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)
source
OrionAuth.get_headersMethod
get_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
source
OrionAuth.get_headersMethod
get_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
source
OrionAuth.handle_auth_exceptionMethod
handle_auth_exception(ex::ResponseException) -> Any

Convert 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()
end
source
OrionAuth.to_http_responseMethod
to_http_response(ex::ResponseException) -> HTTP.Response

Convert ResponseException to HTTP.Response.

Arguments

  • ex::ResponseException: The response exception to convert

Returns

  • HTTP.Response: HTTP response with status, headers, and body
source
OrionAuth.to_oxygen_responseMethod
to_oxygen_response(ex::ResponseException) -> HTTP.Response

Convert ResponseException to HTTP.Response for Oxygen.

Arguments

  • ex::ResponseException: The response exception to convert

Returns

  • HTTP.Response: HTTP response with status, headers, and body
source