Skip to content

Instantly share code, notes, and snippets.

@tvh
Last active August 29, 2015 14:13
Show Gist options
  • Save tvh/f888012114dda0be9165 to your computer and use it in GitHub Desktop.
Save tvh/f888012114dda0be9165 to your computer and use it in GitHub Desktop.
Password OAuth2 Token
-- | Request (via POST method) "Access Token" using Resource Owner Password Credentials Grant.
--
--
fetchAccessTokenPass :: Manager -- ^ HTTP connection manager
-> OAuth2 -- ^ OAuth Data
-> BS.ByteString -- ^ username
-> BS.ByteString -- ^ password
-> IO (OAuth2Result AccessToken) -- ^ Access Token
fetchAccessTokenPass manager oa username password = doJSONPostRequest manager oa uri body
where (uri, body) = accessTokenUrlPass oa username password
accessTokenUrlPass :: OAuth2
-> BS.ByteString -- ^ username
-> BS.ByteString -- ^ password
-> (URI, PostBody) -- ^ access token request URL plus the request body.
accessTokenUrlPass oa username password = (uri, body)
where uri = oauthAccessTokenEndpoint oa
body = transform' [ ("client_id", Just $ oauthClientId oa)
, ("client_secret", Just $ oauthClientSecret oa)
, ("username", Just username)
, ("password", Just password)
, ("redirect_uri", oauthCallback oa)
, ("grant_type", Just "password")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment