oauth2_utils v0.1.0 OAuth2Utils View Source
Util functions for OAuth2 and connected (OpenID Connect, UMA2) standards
Standard sets are the following:
:oauth2
: refers to RFC6749 and all other RFCs published by the IETF:oidc
: refers to OpenID Connect (https://openid.net/developers/specs/):uma2
: refers to User Managed Access specifications published by Kantara initiative Note that regarding origin of values, IETF have precedence over the others.
Link to this section Summary
Functions
Returns the access token types as documented in the IANA registry
Returns the authorization endpoint response types as documented in the IANA registry
Returns the authorization server metadata as documented in the IANA registry and in the Open ID Connect Discovery 1.0 specification
Returns dynamic client registration metadata as documented in the IANA registry
Returns the extension errors as documented in the IANA registry
Returns the grant types as documented in “OAuth 2.0 Dynamic Client Registration Protocol [RFC7591]”
Returns the oauth parameters as documented in the IANA registry
Returns the oauth parameters for a location. The locations are the following:
:authorization_request
,:authorization_response
,:token_request
and:token_response
from the OAuth2 specification:access_token_response
specific value from the OpenID Connect specification:client_request
and:authorization_server_response
specific values from UMA 2.0 specification
Returns the PKCE code challenge methods as documented in the IANA registry
Returns the token endpoint authentication methods as documented in the IANA registry
Returns the token introspection response members as documented in the IANA registry
Returns the token type hints as documented in the IANA registry
Returns the OAuth2 URIs as documented in the IANA registry
Returns true
if the grant type requires the use of the authorization endpoint, false
otherwise
Returns true
is the access token parameter is valid, false
otherwise
Returns true
is the authorization code parameter is valid, false
otherwise
Returns true
if the parameter is a valid client_id, false
otherwise
Returns true
if the parameter is a valid client secret, false
otherwise
Returns true
is the parameter is a valid RFC6749 password parameter,
false
otherwise
Returns true
is the refresh token parameter is valid, false
otherwise
Returns true
is the parameter is a valid RFC6749 username parameter,
false
otherwise
Link to this section Types
authorization_endpoint_response_type() :: String.t()
authorization_server_metadata() :: String.t()
dynamic_client_registration_metadata() :: String.t()
parameter_location() :: :authorization_request | :authorization_response | :token_request | :token_response | :access_token_response | :client_request | :authorization_server_response
pkce_code_challenge_method() :: String.t()
token_endpoint_authentication_method() :: String.t()
token_introspection_response_member() :: String.t()
Link to this section Functions
get_access_token_types(standard_sets()) :: [access_token_type()]
Returns the access token types as documented in the IANA registry
Example
iex> OAuth2Utils.get_access_token_types()
["Bearer"]
get_authorization_endpoint_response_types(standard_sets()) :: [ authorization_endpoint_response_type() ]
Returns the authorization endpoint response types as documented in the IANA registry
Example
iex> OAuth2Utils.get_authorization_endpoint_response_types([:oauth2, :oidc])
["code", "code id_token", "code id_token token", "code token", "id_token",
"id_token token", "none", "token"]
get_authorization_server_metadata(standard_sets()) :: [ authorization_server_metadata() ]
Returns the authorization server metadata as documented in the IANA registry and in the Open ID Connect Discovery 1.0 specification
Example
iex> OAuth2Utils.get_authorization_server_metadata([:oidc])
["require_request_uri_registration", "claims_parameter_supported",
"subject_types_supported", "id_token_encryption_enc_values_supported",
"request_object_encryption_enc_values_supported",
"userinfo_signing_alg_values_supported", "display_values_supported",
"userinfo_encryption_enc_values_supported", "request_uri_parameter_supported",
"request_object_signing_alg_values_supported", "claim_types_supported",
"request_object_encryption_alg_values_supported", "userinfo_endpoint",
"id_token_encryption_alg_values_supported", "claims_locales_supported",
"request_parameter_supported", "userinfo_encryption_alg_values_supported",
"acr_values_supported", "claims_supported",
"id_token_signing_alg_values_supported"]
get_dynamic_client_registration_metadata(standard_sets()) :: [ dynamic_client_registration_metadata() ]
Returns dynamic client registration metadata as documented in the IANA registry
Example
iex> OAuth2Utils.get_dynamic_client_registration_metadata([:oidc])
["default_max_age", "require_auth_time", "userinfo_signed_response_alg",
"userinfo_encrypted_response_enc", "token_endpoint_auth_signing_alg",
"request_object_encryption_alg", "request_uris",
"id_token_signed_response_alg", "request_object_encryption_enc",
"userinfo_encrypted_response_alg", "sector_identifier_uri", "application_type",
"id_token_encrypted_response_alg", "default_acr_values", "subject_type",
"initiate_login_uri", "request_object_signing_alg",
"id_token_encrypted_response_enc"]
get_extension_errors(standard_sets()) :: [extension_error()]
Returns the extension errors as documented in the IANA registry
Example
iex> OAuth2Utils.get_extension_errors([:oidc])
["consent_required", "interaction_required", "invalid_request_object",
"invalid_request_uri", "login_required", "registration_not_supported",
"request_not_supported", "request_uri_not_supported",
"session_selection_required"]
get_grant_types(standard_sets()) :: [grant_type()]
Returns the grant types as documented in “OAuth 2.0 Dynamic Client Registration Protocol [RFC7591]”
Example
iex> OAuth2Utils.get_authorization_server_metadata([:oidc])
iex> OAuth2Utils.get_grant_types()
["authorization_code", "client_credentials", "implicit", "password",
"refresh_token", "urn:ietf:params:oauth:grant-type:jwt-bearer",
"urn:ietf:params:oauth:grant-type:saml2-bearer"]
get_parameters(standard_sets()) :: [parameter()]
Returns the oauth parameters as documented in the IANA registry
Example
iex> OAuth2Utils.get_parameters([:uma2])
["rpt", "pct", "claim_token", "upgraded", "ticket"]
get_parameters_for_location(parameter_location(), standard_sets()) :: [ parameter() ]
Returns the oauth parameters for a location. The locations are the following:
:authorization_request
,:authorization_response
,:token_request
and:token_response
from the OAuth2 specification:access_token_response
specific value from the OpenID Connect specification:client_request
and:authorization_server_response
specific values from UMA 2.0 specification
Example
iex> OAuth2Utils.get_parameters_for_location(:authorization_response, [:oauth2, :oidc])
["error_uri", "error", "error_description", "token_type", "access_token",
"state", "scope", "expires_in", "code", "session_state", "id_token"]
get_pkce_code_challenge_methods(standard_sets()) :: [ pkce_code_challenge_method() ]
Returns the PKCE code challenge methods as documented in the IANA registry
Example
iex> OAuth2Utils.get_pkce_code_challenge_methods()
["S256", "plain"]
get_token_endpoint_authentication_methods(standard_sets()) :: [ token_endpoint_authentication_method() ]
Returns the token endpoint authentication methods as documented in the IANA registry
Example
iex> OAuth2Utils.get_token_endpoint_authentication_methods()
["client_secret_basic", "client_secret_post", "none"]
iex> OAuth2Utils.get_token_endpoint_authentication_methods([:oauth2, :oidc])
["client_secret_basic", "client_secret_jwt", "client_secret_post", "none",
"private_key_jwt"]
get_token_introspection_response_members(standard_sets()) :: [ token_introspection_response_member() ]
Returns the token introspection response members as documented in the IANA registry
Example
iex> OAuth2Utils.get_token_introspection_response_members([:uma2])
["permissions"]
get_token_type_hints(standard_sets()) :: [token_type_hint()]
Returns the token type hints as documented in the IANA registry
Example
iex> OAuth2Utils.get_token_type_hints()
["access_token", "refresh_token"]
get_uris(standard_sets()) :: [uri()]
Returns the OAuth2 URIs as documented in the IANA registry
Example
iex> OAuth2Utils.get_uris()
["urn:ietf:params:oauth:grant-type:jwt-bearer",
"urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"urn:ietf:params:oauth:grant-type:saml2-bearer",
"urn:ietf:params:oauth:client-assertion-type:saml2-bearer",
"urn:ietf:params:oauth:token-type:jwt"]
uses_authorization_endpoint?(grant_type()) :: boolean()
Returns true
if the grant type requires the use of the authorization endpoint, false
otherwise
Example
iex> OAuth2Utils.uses_authorization_endpoint?("implicit")
true
iex> OAuth2Utils.uses_authorization_endpoint?("client_credentials")
false
iex> OAuth2Utils.uses_authorization_endpoint?("password")
false
Returns true
is the access token parameter is valid, false
otherwise
Example
iex> OAuth2Utils.valid_access_token_param?("2YotnFZFEjr1zCsicMWpAA")
true
iex> OAuth2Utils.valid_access_token_param?("2YоtnFZFEjr1zCsicMWpАA")
false
Returns true
is the authorization code parameter is valid, false
otherwise
Example
iex> OAuth2Utils.valid_authorization_code_param?("WIrgzqwBTQrgx*^TcyhBXonuCQ;',oi2~QO")
true
iex> OAuth2Utils.valid_authorization_code_param?("Hï")
false
Returns true
if the parameter is a valid client_id, false
otherwise
Example
iex> OAuth2Utils.valid_client_id_param?("my_client_23")
true
iex> OAuth2Utils.valid_client_id_param?("my_client¯23")
false
valid_client_secret_param?(client_secret()) :: boolean()
Returns true
if the parameter is a valid client secret, false
otherwise
Returns true
is the parameter is a valid RFC6749 password parameter,
false
otherwise
Returns true
is the refresh token parameter is valid, false
otherwise
Example
iex> OAuth2Utils.valid_refresh_token_param?("tGzv3JOkF0XG5Qx2TlKWIA")
true
iex> OAuth2Utils.valid_refresh_token_param?("tGzv3JOkF0XG5Qx2TlKWIA")
false
Returns true
is the parameter is a valid RFC6749 username parameter,
false
otherwise
iex> OAuth2Utils.valid_username_param?("молду")
true
iex> OAuth2Utils.valid_username_param?("john
smith")
false