flwr_oauth2/token_introspection

This module implements RFC7662 Token Introspection. It allows the protected resource to introspect a presented token.

Types

The error types that can occur when parsing the response from the token introspection endpoint.

pub type IntrospectionErrorResponse {
  AuthorizationServerError(response.AuthorizationServerError)
  BearerTokenError(List(bearer_token.BearerErrorResponse))
  InvalidStatus(status: Int)
  ParseError(common.ParseError)
  BearerTokenParseError(bearer_token.BearerTokenParserError)
}

Constructors

  • AuthorizationServerError(response.AuthorizationServerError)

    The client that is used to authorize the request could not be used for authorization.

  • BearerTokenError(List(bearer_token.BearerErrorResponse))

    The bearer token used to authorize the request could not be used for authorization.

  • InvalidStatus(status: Int)

    The response uses a status code not listed in RFC 7662.

  • ParseError(common.ParseError)

    This error indicates that the response contains a response format error, such as an invalid content-type or JSON parse error.

  • BearerTokenParseError(bearer_token.BearerTokenParserError)

    Parsing the WWW-Authenticate header led to an parsing error.

pub type IntrospectionRequest {
  IntrospectionRequest(
    endpoint: uri.Uri,
    token: String,
    token_hint: option.Option(revocation.TokenTypeHint),
  )
}

Constructors

pub type IntrospectionResponse {
  IntrospectionResponse(
    active: Bool,
    scope: List(String),
    client_id: option.Option(common.ClientId),
    username: option.Option(String),
    token_type: option.Option(String),
    expires_at: option.Option(timestamp.Timestamp),
    issued_at: option.Option(timestamp.Timestamp),
    not_before: option.Option(timestamp.Timestamp),
    subject: option.Option(String),
    audience: List(String),
    issuer: option.Option(String),
    jti: option.Option(String),
  )
}

Constructors

Values

pub fn parse_introspection_response(
  response resp: response.Response(String),
) -> Result(IntrospectionResponse, IntrospectionErrorResponse)

Parses the RFC7662 Responses and Error Responses. If the error response code is 401, it will try to parse the WWW-Authenticate header first. If it does not contain any errors regarding a bearer token, it will try to parse the response body. Assumes that a missing content type for a success response means that the response contains a JSON body.

pub fn to_http_request(
  introspection_request: IntrospectionRequest,
) -> Result(request.Request(String), token_request.RequestError)

Implements the token introspection request according to RFC7662. Needs to be combined either with the basic authentication or an bearer token. To attach an access token see the example below:

import flwr_oauth2/bearer_token
import flwr_oauth2/token_introspection.{IntrospectionRequest}
import flwr_oauth2/revocation.{AccessToken}
let intro_req =
  IntrospectionRequest(
    endpoint: todo as "define endpoint",
    token: todo as "define token",
    token_hint: todo as "add token hint if known/required",
  )
let req =
  to_http_request(intro_req)
  |> result.map(bearer_token.attach_bearer_token_string_to_header(
    _,
    "access-token",
  ))
pub fn to_http_request_with_extensions(
  introspection_request: IntrospectionRequest,
  extensions: List(#(String, String)),
) -> Result(request.Request(String), token_request.RequestError)

Same as to_http_request, but allows custom extension to be added to the request body Allows extensions to the body, which are not checked for duplicated or protected attributes.

✨ Search Document