flwr_oauth2/authorization_grant
Types
This defines a redirect url defined by RFC6749 Authorization Code Grant.
pub type AuthorizationCodeGrantRequest {
AuthorizationCodeGrantRequest(
authorization_endpoint: uri.Uri,
response_type: ResponseType,
redirect_uri: option.Option(uri.Uri),
client_id: flwr_oauth2.ClientId,
scope: List(String),
state: option.Option(State),
code_challenge: option.Option(String),
code_challenge_method: option.Option(CodeChallengeMethod),
)
}
Constructors
-
AuthorizationCodeGrantRequest( authorization_endpoint: uri.Uri, response_type: ResponseType, redirect_uri: option.Option(uri.Uri), client_id: flwr_oauth2.ClientId, scope: List(String), state: option.Option(State), code_challenge: option.Option(String), code_challenge_method: option.Option(CodeChallengeMethod), )Represents a redirect url with an optional PKCE code challenge. See RFC7636.
Parsed response when the authorization server redirects back to the caller using the given redirect URI. See Section 4.1.2
pub type AuthorizationResponse {
ImplicitGrantResponse(
state: option.Option(State),
token: flwr_oauth2.AccessTokenResponse,
)
CodeGrantResponse(state: option.Option(State), code: String)
ErrorResponse(
state: option.Option(State),
error: String,
error_description: option.Option(String),
error_uri: option.Option(uri.Uri),
)
}
Constructors
-
ImplicitGrantResponse( state: option.Option(State), token: flwr_oauth2.AccessTokenResponse, ) -
CodeGrantResponse(state: option.Option(State), code: String) -
ErrorResponse( state: option.Option(State), error: String, error_description: option.Option(String), error_uri: option.Option(uri.Uri), )
The kind of code challenge method used for the PKCE extension. See RFC7636 Client Creates Code Challenge
pub type CodeChallengeMethod {
Plain
S256
}
Constructors
-
Plain -
S256
pub type ParseError {
ParseError(field: option.Option(String))
}
Constructors
-
ParseError(field: option.Option(String))Error when a required field is not present on the Authorization Response or the query parameters could not be parsed
Type to indicate the response type of the authorization code and implicit grant. Must always be “code” for the authorizatin code grant and alway be “token” for the implicit grant. For more information see RFC6749.
pub type ResponseType {
Code
Token
}
Constructors
-
Code -
Token
Values
pub fn error_to_string(error: ParseError) -> String
pub fn make_redirect_uri(
redirect_config: AuthorizationCodeGrantRequest,
) -> uri.Uri
Creates the uri that the resource owner should be redirected too.
pub fn new() -> AuthorizationCodeGrantRequest
Creates a new Authorization Code Grant Request, with empty fields. Mostly a convenience function, watch out for empty values!
pub fn parse_authorization_response(
req: request.Request(a),
) -> Result(AuthorizationResponse, ParseError)
Parses the redirect URI, with the code for the code grant type or the access token for the implicit grant type. See Section 4.1.2
pub fn parse_authorization_response_query(
query: dict.Dict(String, String),
) -> Result(AuthorizationResponse, ParseError)
Parses the query from the authorization response HTTP request. This function is intended to be used in case your implementation does not use the standard gleam/http/request type.
pub fn random_state(length: Int) -> State
Generates a random State with the specified length including only uppercase and lowercase letters If length <= 0 returns an empty string
pub fn set_authorization_endpoint(
req: AuthorizationCodeGrantRequest,
authorization_endpoint: uri.Uri,
) -> AuthorizationCodeGrantRequest
pub fn set_client_id(
req: AuthorizationCodeGrantRequest,
client_id: flwr_oauth2.ClientId,
) -> AuthorizationCodeGrantRequest
pub fn set_code_challenge(
req: AuthorizationCodeGrantRequest,
code_challenge: String,
code_challenge_method: CodeChallengeMethod,
) -> AuthorizationCodeGrantRequest
pub fn set_redirect_uri(
req: AuthorizationCodeGrantRequest,
redirect_uri: uri.Uri,
) -> AuthorizationCodeGrantRequest
pub fn set_response_type(
req: AuthorizationCodeGrantRequest,
response_type: ResponseType,
) -> AuthorizationCodeGrantRequest
pub fn set_scope(
req: AuthorizationCodeGrantRequest,
scope: List(String),
) -> AuthorizationCodeGrantRequest
pub fn set_state(
req: AuthorizationCodeGrantRequest,
state: State,
) -> AuthorizationCodeGrantRequest
pub fn to_string(resp: AuthorizationResponse) -> String
Creates a String representation of the AuthorizationResponse
pub fn to_token_request(
authorization_response: AuthorizationResponse,
token_endpoint: uri.Uri,
authentication: flwr_oauth2.ClientAuthentication,
redirect_uri: option.Option(uri.Uri),
) -> Result(flwr_oauth2.TokenRequest, Nil)
Utility function to create a TokenRequest from an AuthorizationResponse. If the AuthorizationResponse is an ErrorResponse or an ImplicitGrantResponse returns Error(Nil), otherwise returns an AuthorizationCodeGrantTokenRequest.