flwr_oauth2/bearer_token

This module aims to fulfill most of RFC6750 for attaching an access token to an HTTP request to a protected resource.

Types

pub type BearerErrorResponse {
  BearerErrorResponse(
    realm: option.Option(String),
    scope: List(String),
    error: option.Option(String),
    error_description: option.Option(String),
    error_uri: option.Option(uri.Uri),
  )
}

Constructors

Values

pub fn attach_access_token_string_to_body(
  req: request.Request(List(#(String, String))),
  access_token: String,
) -> request.Request(List(#(String, String)))
pub fn attach_access_token_string_to_query_parameters(
  req: request.Request(a),
  access_token: String,
) -> request.Request(a)
pub fn attach_access_token_to_body(
  req: request.Request(List(#(String, String))),
  token: response.AccessTokenResponse,
) -> request.Request(List(#(String, String)))

Attach the access token to the body as access token. This function adds the access token to the body of provided request. It does not set the content type to application/x-www-form-urlencoded, but in order to send the body with the access token to a server it has to be set and the body needs to be url encoded. See RFC6750.

pub fn attach_access_token_to_query_parameters(
  req: request.Request(a),
  token: response.AccessTokenResponse,
) -> request.Request(a)

Attach the access token to the query parameters as access token. See RFC6750.

pub fn attach_bearer_token_header(
  req: request.Request(a),
  token: response.AccessTokenResponse,
) -> request.Request(a)

Attach the access token to the Authorization header as Bearer token. See RFC6750.

pub fn attach_bearer_token_string_to_header(
  req: request.Request(a),
  access_token: String,
) -> request.Request(a)
pub fn parse_bearer_error_response(
  response resp: response.Response(a),
) -> Result(List(BearerErrorResponse), Nil)

This method implements RFC6750 to parse error responses. Use this method when requesting a resource from the resource server and it responds with 401 status code. Per RFC6750 when the server responds with 401, the bearer token must not be reused, even if there is no BearerErrorResponse.

✨ Search Document