Assent v0.1.13 Assent.Strategy.OAuth View Source
OAuth strategy.
authorize_url/1
returns a map with a :session_params
and :url
key. The
:session_params
key carries a :oauth_token_secret
value for the request.
Configuration
:consumer_key
- The OAuth consumer key, required:consumer_secret
- The OAuth consumer secret, required:site
- The domain of the OAuth server, required
Usage
config = [
consumer_key: "REPLACE_WITH_CONSUMER_KEY",
consumer_secret: "REPLACE_WITH_CONSUMER_SECRET",
site: "https://auth.example.com",
authorization_params: [scope: "user:read user:write"],
user_url: "https://example.com/api/user"
]
{:ok, {url: url, session_params: session_params}} =
config
|> Assent.Config.put(:redirect_uri, "http://localhost:4000/auth/callback")
|> OAuth.authorize_url()
{:ok, %{user: user, token: token}} =
config
|> Assent.Config.put(:session_params, session_params)
|> OAuth.callback(params)
Link to this section Summary
Functions
Generate authorization URL for request phase.
Callback phase for generating access token and fetch user data.
Makes a HTTP get request to the API.
Link to this section Functions
Link to this function
authorize_url(config)
View Sourceauthorize_url(Assent.Config.t()) :: {:ok, %{url: binary(), session_params: %{oauth_token_secret: binary()}}} | {:error, term()}
Generate authorization URL for request phase.
Configuration
:redirect_uri
- The URI that the server redirects the user to after authentication, required:request_token_url
- The path or URL to fetch the token from, optional, defaults to/oauth/request_token
:authorize_url
- The path or URL for the OAuth server to redirect users to, defaults to/oauth/authenticate
:authorization_params
- The authorization parameters, defaults to[]
Callback phase for generating access token and fetch user data.
Configuration
:access_token_url
- The path or URL to fetch the access token from, optional, defaults to/oauth/access_token
:user_url
- The path or URL to fetch user data, required:session_params
- The session parameters that was returned fromauthorize_url/1
, optional
Makes a HTTP get request to the API.
JSON responses will be decoded to maps.