authable v0.9.1 Authable.GrantType.AuthorizationCode

AuthorizationCode grant type for OAuth2 Authorization Server

Link to this section Summary

Functions

Authorize client for ‘resource owner’ using client credentials and authorization code

Link to this section Functions

Link to this function authorize(arg1)

Authorize client for ‘resource owner’ using client credentials and authorization code.

For authorization, authorize function requires a map contains ‘client_id’, ‘client_secret’, ‘redirect_uri’(must match with authorization code token’s), and ‘code’ keys. With valid credentials; it automatically creates access_token and refresh_token(if enabled via config) then it returns Authable.Model.Token struct, otherwise {:error, Map, :http_status_code}.

Examples

# With OAuth2 optional scope
Authable.GrantType.AuthorizationCode.authorize(%{
  "client_id" => "52024ca6-cf1d-4a9d-bfb6-9bc5023ad56e",
  "client_secret" => "Wi7Y_Q5LU4iIwJArgqXq2Q",
  "redirect_uri" => "http://localhost:4000/oauth2/callbacks",
  "code" => "W_hb8JEDmeYChsNfOGCmbQ",
  "scope" => "read"
})

# Without OAuth2 optional scope
Authable.GrantType.AuthorizationCode.authorize(%{
  "client_id" => "52024ca6-cf1d-4a9d-bfb6-9bc5023ad56e",
  "client_secret" => "Wi7Y_Q5LU4iIwJArgqXq2Q",
  "redirect_uri" => "http://localhost:4000/oauth2/callbacks",
  "code" => "W_hb8JEDmeYChsNfOGCmbQ"
})