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 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

Link to this type access_token_type() View Source
access_token_type() :: String.t()
Link to this type authorization_endpoint_response_type() View Source
authorization_endpoint_response_type() :: String.t()
Link to this type authorization_server_metadata() View Source
authorization_server_metadata() :: String.t()
Link to this type client_id() View Source
client_id() :: String.t()
Link to this type client_secret() View Source
client_secret() :: String.t()
Link to this type dynamic_client_registration_metadata() View Source
dynamic_client_registration_metadata() :: String.t()
Link to this type extension_error() View Source
extension_error() :: String.t()
Link to this type grant_type() View Source
grant_type() :: String.t()
Link to this type parameter() View Source
parameter() :: String.t()
Link to this type parameter_location() View Source
parameter_location() ::
  :authorization_request
  | :authorization_response
  | :token_request
  | :token_response
  | :access_token_response
  | :client_request
  | :authorization_server_response
Link to this type pkce_code_challenge_method() View Source
pkce_code_challenge_method() :: String.t()
Link to this type standard_set() View Source
standard_set() :: :oauth2 | :oidc | :uma2
Link to this type standard_sets() View Source
standard_sets() :: [standard_set()]
Link to this type token_endpoint_authentication_method() View Source
token_endpoint_authentication_method() :: String.t()
Link to this type token_introspection_response_member() View Source
token_introspection_response_member() :: String.t()
Link to this type token_type_hint() View Source
token_type_hint() :: String.t()

Link to this section Functions

Link to this function get_access_token_types(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_authorization_endpoint_response_types(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_authorization_server_metadata(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_dynamic_client_registration_metadata(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_extension_errors(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_grant_types(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_parameters(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_parameters_for_location(location, standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_pkce_code_challenge_methods(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_token_endpoint_authentication_methods(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_token_introspection_response_members(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_token_type_hints(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function get_uris(standard_sets \\ [:oauth2]) View Source
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"]
Link to this function uses_authorization_endpoint?(grant_type) View Source
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
Link to this function valid_access_token_param?(access_token) View Source
valid_access_token_param?(String.t()) :: boolean()

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
Link to this function valid_authorization_code_param?(authorization_code) View Source
valid_authorization_code_param?(String.t()) :: boolean()

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
Link to this function valid_client_id_param?(client_id) View Source
valid_client_id_param?(client_id()) :: boolean()

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
Link to this function valid_client_secret_param?(client_secret) View Source
valid_client_secret_param?(client_secret()) :: boolean()

Returns true if the parameter is a valid client secret, false otherwise

Link to this function valid_password_param?(password) View Source
valid_password_param?(String.t()) :: boolean()

Returns true is the parameter is a valid RFC6749 password parameter, false otherwise

Link to this function valid_refresh_token_param?(refresh_token) View Source
valid_refresh_token_param?(String.t()) :: boolean()

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
Link to this function valid_username_param?(username) View Source
valid_username_param?(String.t()) :: boolean()

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