OAuth2.Client
OAuth2 Client
This module is responsible for building and establishing a request for an access token.
Summary↑
authorize_url!(client, params \\ []) | Calls |
authorize_url(client, params \\ []) | The authorize endpoint URL of the OAuth2 provider |
get_token!(client, params \\ [], headers \\ []) | Calls |
get_token(client, params \\ [], headers \\ []) | Initializes an AccessToken by making a request to the token endpoint |
merge_params(client, params) | Set multiple params in the client in one call |
new(opts) | Builds a new OAuth2 client struct using the |
put_header(client, key, value) | Adds a new header |
put_headers(client, list2) | Set multiple headers in the client in one call |
put_param(client, key, value) | Puts the specified |
Types ↑
strategy :: module
client_id :: binary
client_secret :: binary
site :: binary
authorize_url :: binary
token_url :: binary
token_method :: :post | :get | atom
redirect_uri :: binary
headers :: [{binary, binary}]
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}
Functions
Specs:
- authorize_url(t, list) :: binary
The authorize endpoint URL of the OAuth2 provider
Specs:
- authorize_url!(t, list) :: binary
Calls authorize_url/2
but raises Error
if an error occurs.
Initializes an AccessToken by making a request to the token endpoint.
Returns an AccessToken
struct that can then be used to access the resource API.
Arguments
client
- a struct of the strategy in use, defaults toOAuth2.Strategy.AuthCode
params
- a keyword list of request parametersheaders
- a list of request headers
Specs:
- get_token!(t, params, headers) :: OAuth2.Response.t | OAuth2.Error.t
Calls get_token/3
but raises Error
if there an error occurs.
Specs:
- merge_params(t, OAuth2.params) :: t
Set multiple params in the client in one call.
Specs:
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, default"/oauth/authorize"
token_url
- absolute or relative URL path to the token endpoint, default"/oauth/token"
token_method
- HTTP method to use to request token (:get or :post), default: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
Specs:
Adds a new header key
if not present, otherwise replaces the
previous value of that header with value
.
Specs:
Set multiple headers in the client in one call.
Specs:
Puts the specified value
in the params for the given key
.
The key can be a string or an atom, atoms are automatically convert to strings.