Skip to content

Instantly share code, notes, and snippets.

@scrogson
Created August 27, 2014 05:42
Show Gist options
  • Save scrogson/f664dc6f5366011d3939 to your computer and use it in GitHub Desktop.
Save scrogson/f664dc6f5366011d3939 to your computer and use it in GitHub Desktop.
defmodule OAuth2.Strategy.Password do
@moduledoc """
The Resource Owner Password Credentials Authorization Strategy.
http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-4.3
"""
use OAuth2.Strategy
@doc """
Not used for this strategy.
"""
def authorize_url do
raise "Not implemented."
end
@doc """
Retrieve an access token given the specified End User username and password.
"""
def get_token(client, username, password, params \\ %{}, opts \\ %{}) do
params =
%{grant_type: "password", username: username, password: password}
|> Map.merge(Map.take(client, [:client_id, :client_secret]))
|> Map.merge(params)
Client.get_token(client, params, opts)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment