OAuth2.Client

OAuth2 Client

This module is responsible for building and establishing a request for an access token.

Source

Summary

authorize_url!(client, params \\ [])

Calls authorize_url/2 but raises Error if an error occurs

authorize_url(client, params \\ [])

The authorize endpoint URL of the OAuth2 provider

get_token!(client, params \\ [], headers \\ [])

Calls get_token/3 but raises Error if there an error occurs

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

put_header(client, key, value)

Adds a new header key if not present, otherwise replaces the previous value of that header with value

put_headers(client, list2)

Set multiple headers in the client in one call

put_param(client, key, value)

Puts the specified value in the params for the given key

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

param :: binary | %{binary => param} | [param]

params :: %{binary => param}

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

authorize_url(client, params \\ [])

Specs:

  • authorize_url(t, list) :: binary

The authorize endpoint URL of the OAuth2 provider

Source
authorize_url!(client, params \\ [])

Specs:

  • authorize_url!(t, list) :: binary

Calls authorize_url/2 but raises Error if an error occurs.

Source
get_token(client, params \\ [], headers \\ [])

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 to OAuth2.Strategy.AuthCode
  • params - a keyword list of request parameters
  • headers - a list of request headers
Source
get_token!(client, params \\ [], headers \\ [])

Specs:

Calls get_token/3 but raises Error if there an error occurs.

Source
merge_params(client, params)

Specs:

Set multiple params in the client in one call.

Source
new(opts)

Specs:

Builds a new OAuth2 client struct using the opts provided.

Client struct fields

  • strategy - a module that implements the appropriate OAuth2 strategy, default OAuth2.Strategy.AuthCode
  • client_id - the client_id for the OAuth2 provider
  • client_secret - the client_secret for the OAuth2 provider
  • site - the OAuth2 provider site host
  • authorize_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 parameters
  • headers: a list of request headers
  • redirect_uri: the URI the provider should redirect to after authorization or token requests
Source
put_header(client, key, value)

Specs:

  • put_header(t, binary, binary) :: t

Adds a new header key if not present, otherwise replaces the previous value of that header with value.

Source
put_headers(client, list2)

Specs:

  • put_headers(t, list) :: t

Set multiple headers in the client in one call.

Source
put_param(client, key, value)

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.

Source