Update Nylas provider

- Nylas now requires additional parameters for authentication to succeed
- We remove oauth2NylasScoped because it wasn't exported, and Nylas does
  not support any scopes other than "email"
This commit is contained in:
Brian Schroeder 2017-07-27 23:36:09 -04:00 committed by patrick brisbin
parent e756d88e1b
commit de589f8cb6

View File

@ -23,8 +23,6 @@ import Yesod.Auth (Creds(..), YesodAuth, AuthPlugin)
import Yesod.Auth.OAuth2 (OAuth2(..), AccessToken(..)
, YesodOAuth2Exception(InvalidProfileResponse)
, authOAuth2)
import qualified Data.Text as T
import qualified Network.HTTP.Types as HT
data NylasAccount = NylasAccount
@ -48,25 +46,16 @@ oauth2Nylas :: YesodAuth m
=> Text -- ^ Client ID
-> Text -- ^ Client Secret
-> AuthPlugin m
oauth2Nylas = oauth2NylasScoped ["email"]
oauth2NylasScoped :: YesodAuth m
=> [Text] -- ^ Scopes
-> Text -- ^ Client ID
-> Text -- ^ Client Secret
-> AuthPlugin m
oauth2NylasScoped scopes clientId clientSecret =
authOAuth2 "nylas" oauth fetchCreds
oauth2Nylas clientId clientSecret = authOAuth2 "nylas" oauth fetchCreds
where
authorizeUrl = encodeUtf8
$ "https://api.nylas.com/oauth/authorize?scope="
<> T.intercalate "," scopes
tokenUrl = "https://api.nylas.com/oauth/token"
authorizeUrl = encodeUtf8 $ "https://api.nylas.com/oauth/authorize" <>
"?response_type=code&scope=email&client_id=" <> clientId
oauth = OAuth2
{ oauthClientId = encodeUtf8 clientId
, oauthClientSecret = encodeUtf8 clientSecret
, oauthOAuthorizeEndpoint = authorizeUrl
, oauthAccessTokenEndpoint = tokenUrl
, oauthAccessTokenEndpoint = "https://api.nylas.com/oauth/token"
, oauthCallback = Nothing
}