Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data OAuth2Client = OAuth2Client {
- clientId :: !String
- clientSecret :: !String
- type OAuth2Code = String
- type OAuth2Scope = String
- type OAuth2Token = String
- data OAuth2Tokens = OAuth2Tokens {
- accessToken :: !OAuth2Token
- refreshToken :: !OAuth2Token
- expiresIn :: !Int
- tokenType :: !String
- getAccessToken :: OAuth2Client -> [OAuth2Scope] -> Maybe FilePath -> IO OAuth2Token
- newTokens :: OAuth2Client -> [OAuth2Scope] -> IO OAuth2Tokens
- refreshTokens :: OAuth2Client -> OAuth2Tokens -> IO OAuth2Tokens
- promptForCode :: OAuth2Client -> [OAuth2Scope] -> IO OAuth2Code
- exchangeCode :: OAuth2Client -> OAuth2Code -> IO OAuth2Tokens
Types
data OAuth2Client Source
OAuth2 client definition
https://developers.google.com/console/help/new/#generatingoauth2
OAuth2Client | |
|
type OAuth2Code = String Source
type OAuth2Scope = String Source
type OAuth2Token = String Source
data OAuth2Tokens Source
OAuth2Tokens | |
|
Getting an access token
:: OAuth2Client | |
-> [OAuth2Scope] | |
-> Maybe FilePath | File in which to cache the token |
-> IO OAuth2Token | Refreshed token |
Get a valid access token with the given scopes
If given, credentials are cached in a file, thus preventing the need for any prompting on subsequent reuse. N.B. this function always refreshes the access token before returning it.
Lower-level steps
newTokens :: OAuth2Client -> [OAuth2Scope] -> IO OAuth2Tokens Source
Prompt the user for a verification code and exchange it for tokens
refreshTokens :: OAuth2Client -> OAuth2Tokens -> IO OAuth2Tokens Source
Use the refresh token to get a new access token
promptForCode :: OAuth2Client -> [OAuth2Scope] -> IO OAuth2Code Source
Prompt the user for a verification code
exchangeCode :: OAuth2Client -> OAuth2Code -> IO OAuth2Tokens Source
Exchange a verification code for tokens