View Source AshAuthentication.Strategy.Github (ash_authentication v3.11.13)
Strategy for authenticating using GitHub
This strategy builds on-top of AshAuthentication.Strategy.OAuth2 and
assent.
In order to use GitHub you need to provide the following minimum configuration:
client_idredirect_uriclient_secret
See the GitHub quickstart guide for more information.
DSL Documentation
Provides a pre-configured authentication strategy for GitHub.
This strategy is built using the :oauth2 strategy, and thus provides all the same
configuration options should you need them.
For more information see the Github Quick Start Guide in our documentation.
Strategy defaults:
The following defaults are applied:
:siteis set to"https://api.github.com".:authorize_urlis set to"https://github.com/login/oauth/authorize".:token_urlis set to"https://github.com/login/oauth/access_token".:user_urlis set to"/user".:user_emails_urlis set to"/user/emails".:authorization_paramsis set to[scope: "read:user,user:email"].:auth_methodis set to:client_secret_post.
Schema:
:name(atom/0) - Required. Uniquely identifies the strategy.:client_id- Required. The OAuth2 client ID.
Takes either a module which implements theAshAuthentication.Secretbehaviour, a 2 arity anonymous function or a string.
See the module documentation forAshAuthentication.Secretfor more information.Example:
client_id fn _, resource -> :my_app |> Application.get_env(resource, []) |> Keyword.fetch(:oauth_client_id) end:site- Required. The base URL of the OAuth2 server - including the leading protocol (iehttps://).
Takes either a module which implements theAshAuthentication.Secretbehaviour, a 2 arity anonymous function or a string.
See the module documentation forAshAuthentication.Secretfor more information.Example:
site fn _, resource -> :my_app |> Application.get_env(resource, []) |> Keyword.fetch(:oauth_site) end:auth_method- The authentication strategy used, optional. If not set, no authentication will be used during the access token request. The value may be one of the following::client_secret_basic:client_secret_post:client_secret_jwt:private_key_jwtValid values are nil, :client_secret_basic, :client_secret_post, :client_secret_jwt, :private_key_jwt The default value is:client_secret_post.
:client_secret- The OAuth2 client secret.
Required if :auth_method is:client_secret_basic,:client_secret_postor:client_secret_jwt.
Takes either a module which implements theAshAuthentication.Secretbehaviour, a 2 arity anonymous function or a string.
See the module documentation forAshAuthentication.Secretfor more information.Example:
site fn _, resource -> :my_app |> Application.get_env(resource, []) |> Keyword.fetch(:oauth_site) end:authorize_url- Required. The API url to the OAuth2 authorize endpoint.
Relative to the value ofsite.
Takes either a module which implements theAshAuthentication.Secretbehaviour, a 2 arity anonymous function or a string.
See the module documentation forAshAuthentication.Secretfor more information.Example:
authorize_url fn _, _ -> {:ok, "https://exampe.com/authorize"} end:token_url- Required. The API url to access the token endpoint.
Relative to the value ofsite.
Takes either a module which implements theAshAuthentication.Secretbehaviour, a 2 arity anonymous function or a string.
See the module documentation forAshAuthentication.Secretfor more information.Example:
token_url fn _, _ -> {:ok, "https://example.com/oauth_token"} end:user_url- Required. The API url to access the user endpoint.
Relative to the value ofsite.
Takes either a module which implements theAshAuthentication.Secretbehaviour, a 2 arity anonymous function or a string.
See the module documentation forAshAuthentication.Secretfor more information.Example:
user_url fn _, _ -> {:ok, "https://example.com/userinfo"} end:private_key- The private key to use if:auth_methodis:private_key_jwt
Takes either a module which implements theAshAuthentication.Secretbehaviour, a 2 arity anonymous function or a string.
See the module documentation forAshAuthentication.Secretfor more information.:redirect_uri- Required. The callback URI base.
Not the whole URI back to the callback endpoint, but the URI to yourAuthPlug. We can generate the rest.
Whilst not particularly secret, it seemed prudent to allow this to be configured dynamically so that you can use different URIs for different environments.
Takes either a module which implements theAshAuthentication.Secretbehaviour, a 2 arity anonymous function or a string.
See the module documentation forAshAuthentication.Secretfor more information.:authorization_params(keyword/0) - Any additional parameters to encode in the request phase.
eg:authorization_params scope: "openid profile email"The default value is[].:registration_enabled?(boolean/0) - Is registration enabled for this provider?
If this option is enabled, then new users will be able to register for your site when authenticating and not already present.
If not, then only existing users will be able to authenticate. The default value istrue.:register_action_name(atom/0) - The name of the action to use to register a user.
Only needed ifregistration_enabled?istrue.
Because we we don't know the response format of the server, you must implement your own registration action of the same name.
See the "Registration and Sign-in" section of the module documentation for more information.
The default is computed from the strategy name eg:register_with_#{name}.:sign_in_action_name(atom/0) - The name of the action to use to sign in an existing user.
Only needed ifregistration_enabled?isfalse.
Because we don't know the response format of the server, you must implement your own sign-in action of the same name.
See the "Registration and Sign-in" section of the module documentation for more information.
The default is computed from the strategy name, eg:sign_in_with_#{name}.:identity_resource- The resource used to store user identities.
Given that a user can be signed into multiple different authentication providers at once we use theAshAuthentication.UserIdentityresource to build a mapping between users, providers and that provider's uid.
See the Identities section of the module documentation for more information.
Set tofalseto disable. The default value isfalse.:identity_relationship_name(atom/0) - Name of the relationship to the provider identities resource The default value is:identities.:identity_relationship_user_id_attribute(atom/0) - The name of the destination (user_id) attribute on your provider identity resource.
The only reason to change this would be if you changed theuser_id_attribute_nameoption of the provider identity. The default value is:user_id.:icon(atom/0) - The name of an icon to use in any potential UI.
This is a hint for UI generators to use, and not in any way canonical. The default value is:oauth2.
Summary
Functions
Callback implementation for AshAuthentication.Strategy.Custom.transform/2.
Callback implementation for AshAuthentication.Strategy.Custom.verify/2.
Functions
Callback implementation for AshAuthentication.Strategy.Custom.transform/2.
Callback implementation for AshAuthentication.Strategy.Custom.verify/2.