flwr_oauth2/token_request

Types

Type for functions that can set the authorization part of a request. Can be used to customize how authorization is applied to an OAuth request.

pub type AuthorizationSetter {
  AuthorizationSetter(
    setter: fn(request.Request(List(#(String, String)))) -> Result(
      request.Request(List(#(String, String))),
      RequestError,
    ),
  )
}

Constructors

Errors returned by this module when creating requests

pub type RequestError {
  SecretExpired
  InvalidUri
}

Constructors

  • SecretExpired

    Will be returned if an expired secret is used.

  • InvalidUri

    Will be returned if an invalid URL is provided

pub type RequestModifier =
  fn(request.Request(List(#(String, String)))) -> Result(
    request.Request(List(#(String, String))),
    RequestError,
  )

The essential requests of OAuth 2.0. The token requests includes all the different Grant Types defined in RFC6749.

pub type TokenRequest {
  AuthorizationCodeGrantTokenRequest(
    token_endpoint: uri.Uri,
    authentication: authentication.ClientAuthentication,
    redirect_uri: option.Option(uri.Uri),
    code: String,
  )
  ResourceOwnerCredentialsGrantTokenRequest(
    token_endpoint: uri.Uri,
    authentication: authentication.ClientAuthentication,
    username: String,
    password: String,
    scope: List(String),
  )
  RefreshTokenGrantRequest(
    token_endpoint: uri.Uri,
    authentication: authentication.ClientAuthentication,
    refresh_token: String,
    scope: List(String),
  )
  ClientCredentialsGrantTokenRequest(
    token_endpoint: uri.Uri,
    authentication: authentication.ClientAuthentication,
    scope: List(String),
  )
}

Constructors

Type alias for URL encoded http requests.

pub type UrlEncRequest =
  request.Request(List(#(String, String)))

Values

pub fn apply_modifiers(
  request: request.Request(List(#(String, String))),
  modifiers: List(
    fn(request.Request(List(#(String, String)))) -> Result(
      request.Request(List(#(String, String))),
      RequestError,
    ),
  ),
) -> Result(
  request.Request(List(#(String, String))),
  RequestError,
)
pub fn authorization_setter(
  auth: authentication.ClientAuthentication,
) -> fn(request.Request(List(#(String, String)))) -> Result(
  request.Request(List(#(String, String))),
  RequestError,
)

Encodes the ClientAuthentication that is to be sent to the OAuth 2.0 Server. For Basic Authentication it will always encode it with base64.

pub fn build_post_request(
  endpoint: uri.Uri,
  body: List(#(String, String)),
  authentication: authentication.ClientAuthentication,
  modifiers: List(
    fn(request.Request(List(#(String, String)))) -> Result(
      request.Request(List(#(String, String))),
      RequestError,
    ),
  ),
) -> Result(request.Request(String), RequestError)

Build a POST request for an OAuth 2.0 endpoint with the given form-encoded body, authentication, and optional modifiers. This is a lower-level alternative to [to_http_request_with_modifiers] that does not require a [TokenRequest] type — useful for modules that need to construct requests with custom body content (e.g., revocation, assertion grants).

pub fn request_body_to_string(
  request: request.Request(List(#(String, String))),
) -> request.Request(String)
pub fn setup_request(
  endpoint endpoint: uri.Uri,
  body body: List(#(String, String)),
) -> Result(
  request.Request(List(#(String, String))),
  RequestError,
)

A helper function that maps a general request with credentials to a gleam http request. The credentials are either attached to the request body URL encoded or added as basic authorization header.

pub fn to_http_request(
  request: TokenRequest,
) -> Result(request.Request(String), RequestError)

Creates a http request from the given TokenRequest applying the given modifiers, but does not send it. Sending the request is done by the user of the function.

pub fn to_http_request_with_custom_authentication(
  request: TokenRequest,
  modifiers: List(
    fn(request.Request(List(#(String, String)))) -> Result(
      request.Request(List(#(String, String))),
      RequestError,
    ),
  ),
) -> Result(request.Request(String), RequestError)
pub fn to_http_request_with_modifiers(
  request: TokenRequest,
  modifiers: List(
    fn(request.Request(List(#(String, String)))) -> Result(
      request.Request(List(#(String, String))),
      RequestError,
    ),
  ),
) -> Result(request.Request(String), RequestError)

Creates a http request from the given TokenRequest applying the given modifiers, but does not send it. Sending the request is done by the user of the function.

pub fn to_string(req: TokenRequest) -> String
Search Document