OAuth2.Client
This module defines the OAuth2.Client
struct and is responsible for building
and establishing a request for an access token.
Summary
Functions
Returns the authorize url based on the client configuration
Initializes an OAuth2.AccessToken
struct by making a request to the token
endpoint
Same as get_token/4
but raises OAuth2.Error
if an error occurs during the
request
Set multiple params in the client in one call
Builds a new OAuth2 client struct using the opts
provided
Adds a new header key
if not present, otherwise replaces the
previous value of that header with value
Set multiple headers in the client in one call
Puts the specified value
in the params for the given key
Types
client_id :: binary
client_secret :: binary
headers :: [{binary, binary}]
redirect_uri :: binary
site :: binary
strategy :: module
t :: %OAuth2.Client{strategy: strategy, client_id: client_id, client_secret: client_secret, site: site, authorize_url: authorize_url, token_url: token_url, token_method: token_method, params: params, headers: headers, redirect_uri: redirect_uri}
token_method :: :post | :get | atom
token_url :: binary
Functions
Specs
authorize_url!(t, list) :: binary
Returns the authorize url based on the client configuration.
Example
redirect_url = OAuth2.Client.authorize_url!(%OAuth2.Client{})
Specs
get_token(t, params, headers, Keyword.t) ::
{:ok, OAuth2.AccessToken.t} |
{:error, OAuth2.Error.t}
Initializes an OAuth2.AccessToken
struct by making a request to the token
endpoint.
Returns an OAuth2.AccessToken
struct that can then be used to access the
provider’s RESTful API.
Arguments
client
- aOAuth2.Client
struct with the strategy to use, defaults toOAuth2.Strategy.AuthCode
params
- a keyword list of request parametersheaders
- a list of request headersopts
- aKeyword
list of options
Options
:timeout
- the timeout (in milliseconds) of the request:proxy
- a proxy to be used for the request; it can be a regular url or a{Host, Proxy}
tuple
Specs
get_token!(t, params, headers, Keyword.t) ::
OAuth2.AccessToken.t |
OAuth2.Error.t
Same as get_token/4
but raises OAuth2.Error
if an error occurs during the
request.
Specs
merge_params(t, OAuth2.params) :: t
Set multiple params in the client in one call.
Builds a new OAuth2 client struct using the opts
provided.
Client struct fields
strategy
- a module that implements the appropriate OAuth2 strategy, defaultOAuth2.Strategy.AuthCode
client_id
- the client_id for the OAuth2 providerclient_secret
- the client_secret for the OAuth2 providersite
- the OAuth2 provider site hostauthorize_url
- absolute or relative URL path to the authorization endpoint. Defaults to"/oauth/authorize"
token_url
- absolute or relative URL path to the token endpoint. Defaults to"/oauth/token"
token_method
- HTTP method to use to request token (:get
or:post
). Defaults to:post
params
- a map of request parametersheaders
- a list of request headersredirect_uri
- the URI the provider should redirect to after authorization or token requests
Adds a new header key
if not present, otherwise replaces the
previous value of that header with value
.
Set multiple headers in the client in one call.