Reformat with Brittany

This commit is contained in:
patrick brisbin 2020-08-23 13:53:58 -04:00
parent 236d0f4b10
commit c939633a96
12 changed files with 158 additions and 105 deletions

View File

@ -9,7 +9,8 @@
module Yesod.Auth.OAuth2.AzureAD module Yesod.Auth.OAuth2.AzureAD
( oauth2AzureAD ( oauth2AzureAD
, oauth2AzureADScoped , oauth2AzureADScoped
) where )
where
import Prelude import Prelude
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -17,8 +18,7 @@ import Yesod.Auth.OAuth2.Prelude
newtype User = User Text newtype User = User Text
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "mail"
<$> o .: "mail"
pluginName :: Text pluginName :: Text
pluginName = "azuread" pluginName = "azuread"
@ -32,8 +32,11 @@ oauth2AzureAD = oauth2AzureADScoped defaultScopes
oauth2AzureADScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m oauth2AzureADScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
oauth2AzureADScoped scopes clientId clientSecret = oauth2AzureADScoped scopes clientId clientSecret =
authOAuth2 pluginName oauth2 $ \manager token -> do authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- (User userId, userResponse) <- authGetProfile
authGetProfile pluginName manager token "https://graph.microsoft.com/v1.0/me" pluginName
manager
token
"https://graph.microsoft.com/v1.0/me"
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName
@ -44,10 +47,12 @@ oauth2AzureADScoped scopes clientId clientSecret =
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "https://login.windows.net/common/oauth2/authorize" `withQuery` , oauthOAuthorizeEndpoint =
[ scopeParam "," scopes "https://login.windows.net/common/oauth2/authorize"
, ("resource", "https://graph.microsoft.com") `withQuery` [ scopeParam "," scopes
] , ("resource", "https://graph.microsoft.com")
, oauthAccessTokenEndpoint = "https://login.windows.net/common/oauth2/token" ]
, oauthAccessTokenEndpoint =
"https://login.windows.net/common/oauth2/token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -11,7 +11,8 @@
module Yesod.Auth.OAuth2.BattleNet module Yesod.Auth.OAuth2.BattleNet
( oauth2BattleNet ( oauth2BattleNet
, oAuth2BattleNet , oAuth2BattleNet
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -21,8 +22,7 @@ import Yesod.Core.Widget
newtype User = User Int newtype User = User Int
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "id"
<$> o .: "id"
pluginName :: Text pluginName :: Text
pluginName = "battle.net" pluginName = "battle.net"
@ -38,7 +38,10 @@ oauth2BattleNet widget region clientId clientSecret =
authOAuth2Widget widget pluginName oauth2 $ \manager token -> do authOAuth2Widget widget pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- (User userId, userResponse) <-
authGetProfile pluginName manager token authGetProfile pluginName manager token
$ fromRelative "https" (apiHost $ T.toLower region) "/account/user" $ fromRelative
"https"
(apiHost $ T.toLower region)
"/account/user"
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName
@ -64,6 +67,7 @@ wwwHost :: Text -> Host
wwwHost "cn" = "www.battlenet.com.cn" wwwHost "cn" = "www.battlenet.com.cn"
wwwHost region = Host $ encodeUtf8 $ region <> ".battle.net" wwwHost region = Host $ encodeUtf8 $ region <> ".battle.net"
oAuth2BattleNet :: YesodAuth m => Text -> Text -> Text -> WidgetFor m () -> AuthPlugin m oAuth2BattleNet
:: YesodAuth m => Text -> Text -> Text -> WidgetFor m () -> AuthPlugin m
oAuth2BattleNet i s r w = oauth2BattleNet w r i s oAuth2BattleNet i s r w = oauth2BattleNet w r i s
{-# DEPRECATED oAuth2BattleNet "Use oauth2BattleNet" #-} {-# DEPRECATED oAuth2BattleNet "Use oauth2BattleNet" #-}

View File

@ -9,7 +9,8 @@
module Yesod.Auth.OAuth2.Bitbucket module Yesod.Auth.OAuth2.Bitbucket
( oauth2Bitbucket ( oauth2Bitbucket
, oauth2BitbucketScoped , oauth2BitbucketScoped
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -18,8 +19,7 @@ import qualified Data.Text as T
newtype User = User Text newtype User = User Text
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "uuid"
<$> o .: "uuid"
pluginName :: Text pluginName :: Text
pluginName = "bitbucket" pluginName = "bitbucket"
@ -33,8 +33,11 @@ oauth2Bitbucket = oauth2BitbucketScoped defaultScopes
oauth2BitbucketScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m oauth2BitbucketScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
oauth2BitbucketScoped scopes clientId clientSecret = oauth2BitbucketScoped scopes clientId clientSecret =
authOAuth2 pluginName oauth2 $ \manager token -> do authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- (User userId, userResponse) <- authGetProfile
authGetProfile pluginName manager token "https://api.bitbucket.com/2.0/user" pluginName
manager
token
"https://api.bitbucket.com/2.0/user"
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName
@ -51,9 +54,10 @@ oauth2BitbucketScoped scopes clientId clientSecret =
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "https://bitbucket.com/site/oauth2/authorize" `withQuery` , oauthOAuthorizeEndpoint =
[ scopeParam "," scopes "https://bitbucket.com/site/oauth2/authorize"
] `withQuery` [scopeParam "," scopes]
, oauthAccessTokenEndpoint = "https://bitbucket.com/site/oauth2/access_token" , oauthAccessTokenEndpoint =
"https://bitbucket.com/site/oauth2/access_token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -11,7 +11,8 @@ module Yesod.Auth.OAuth2.EveOnline
( oauth2Eve ( oauth2Eve
, oauth2EveScoped , oauth2EveScoped
, WidgetType(..) , WidgetType(..)
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -21,8 +22,7 @@ import Yesod.Core.Widget
newtype User = User Text newtype User = User Text
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "CharacterOwnerHash"
<$> o .: "CharacterOwnerHash"
data WidgetType m data WidgetType m
= Plain -- ^ Simple "Login via eveonline" text = Plain -- ^ Simple "Login via eveonline" text
@ -34,10 +34,14 @@ data WidgetType m
asWidget :: YesodAuth m => WidgetType m -> WidgetFor m () asWidget :: YesodAuth m => WidgetType m -> WidgetFor m ()
asWidget Plain = [whamlet|Login via eveonline|] asWidget Plain = [whamlet|Login via eveonline|]
asWidget BigWhite = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/4PTzeiAshqiM8osU2giO0Y/5cc4cb60bac52422da2e45db87b6819c/EVE_SSO_Login_Buttons_Large_White.png?w=270&h=45">|] asWidget BigWhite =
asWidget BigBlack = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/4fSjj56uD6CYwYyus4KmES/4f6385c91e6de56274d99496e6adebab/EVE_SSO_Login_Buttons_Large_Black.png?w=270&h=45">|] [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/4PTzeiAshqiM8osU2giO0Y/5cc4cb60bac52422da2e45db87b6819c/EVE_SSO_Login_Buttons_Large_White.png?w=270&h=45">|]
asWidget SmallWhite = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/18BxKSXCymyqY4QKo8KwKe/c2bdded6118472dd587c8107f24104d7/EVE_SSO_Login_Buttons_Small_White.png?w=195&h=30">|] asWidget BigBlack
asWidget SmallBlack = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/12vrPsIMBQi28QwCGOAqGk/33234da7672c6b0cdca394fc8e0b1c2b/EVE_SSO_Login_Buttons_Small_Black.png?w=195&h=30">|] = [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/4fSjj56uD6CYwYyus4KmES/4f6385c91e6de56274d99496e6adebab/EVE_SSO_Login_Buttons_Large_Black.png?w=270&h=45">|]
asWidget SmallWhite
= [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/18BxKSXCymyqY4QKo8KwKe/c2bdded6118472dd587c8107f24104d7/EVE_SSO_Login_Buttons_Small_White.png?w=195&h=30">|]
asWidget SmallBlack
= [whamlet|<img src="https://images.contentful.com/idjq7aai9ylm/12vrPsIMBQi28QwCGOAqGk/33234da7672c6b0cdca394fc8e0b1c2b/EVE_SSO_Login_Buttons_Small_Black.png?w=195&h=30">|]
asWidget (Custom a) = a asWidget (Custom a) = a
pluginName :: Text pluginName :: Text
@ -49,26 +53,30 @@ defaultScopes = ["publicData"]
oauth2Eve :: YesodAuth m => WidgetType m -> Text -> Text -> AuthPlugin m oauth2Eve :: YesodAuth m => WidgetType m -> Text -> Text -> AuthPlugin m
oauth2Eve = oauth2EveScoped defaultScopes oauth2Eve = oauth2EveScoped defaultScopes
oauth2EveScoped :: YesodAuth m => [Text] -> WidgetType m -> Text -> Text -> AuthPlugin m oauth2EveScoped
:: YesodAuth m => [Text] -> WidgetType m -> Text -> Text -> AuthPlugin m
oauth2EveScoped scopes widgetType clientId clientSecret = oauth2EveScoped scopes widgetType clientId clientSecret =
authOAuth2Widget (asWidget widgetType) pluginName oauth2 $ \manager token -> do authOAuth2Widget (asWidget widgetType) pluginName oauth2
(User userId, userResponse) <- $ \manager token -> do
authGetProfile pluginName manager token "https://login.eveonline.com/oauth/verify" (User userId, userResponse) <- authGetProfile
pluginName
manager
token
"https://login.eveonline.com/oauth/verify"
pure Creds pure Creds
{ credsPlugin = "eveonline" { credsPlugin = "eveonline"
-- FIXME: Preserved bug. See similar comment in Bitbucket provider. -- FIXME: Preserved bug. See similar comment in Bitbucket provider.
, credsIdent = T.pack $ show userId , credsIdent = T.pack $ show userId
, credsExtra = setExtra token userResponse , credsExtra = setExtra token userResponse
} }
where where
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "https://login.eveonline.com/oauth/authorize" `withQuery` , oauthOAuthorizeEndpoint =
[ ("response_type", "code") "https://login.eveonline.com/oauth/authorize"
, scopeParam " " scopes `withQuery` [("response_type", "code"), scopeParam " " scopes]
]
, oauthAccessTokenEndpoint = "https://login.eveonline.com/oauth/token" , oauthAccessTokenEndpoint = "https://login.eveonline.com/oauth/token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -9,7 +9,8 @@
module Yesod.Auth.OAuth2.GitHub module Yesod.Auth.OAuth2.GitHub
( oauth2GitHub ( oauth2GitHub
, oauth2GitHubScoped , oauth2GitHubScoped
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -18,8 +19,7 @@ import qualified Data.Text as T
newtype User = User Int newtype User = User Int
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "id"
<$> o .: "id"
pluginName :: Text pluginName :: Text
pluginName = "github" pluginName = "github"
@ -33,8 +33,11 @@ oauth2GitHub = oauth2GitHubScoped defaultScopes
oauth2GitHubScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m oauth2GitHubScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
oauth2GitHubScoped scopes clientId clientSecret = oauth2GitHubScoped scopes clientId clientSecret =
authOAuth2 pluginName oauth2 $ \manager token -> do authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- (User userId, userResponse) <- authGetProfile
authGetProfile pluginName manager token "https://api.github.com/user" pluginName
manager
token
"https://api.github.com/user"
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName
@ -45,9 +48,10 @@ oauth2GitHubScoped scopes clientId clientSecret =
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "https://github.com/login/oauth/authorize" `withQuery` , oauthOAuthorizeEndpoint =
[ scopeParam "," scopes "https://github.com/login/oauth/authorize"
] `withQuery` [scopeParam "," scopes]
, oauthAccessTokenEndpoint = "https://github.com/login/oauth/access_token" , oauthAccessTokenEndpoint =
"https://github.com/login/oauth/access_token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -4,7 +4,8 @@ module Yesod.Auth.OAuth2.GitLab
, oauth2GitLabHostScopes , oauth2GitLabHostScopes
, defaultHost , defaultHost
, defaultScopes , defaultScopes
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -13,8 +14,7 @@ import qualified Data.Text as T
newtype User = User Int newtype User = User Int
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "id"
<$> o .: "id"
pluginName :: Text pluginName :: Text
pluginName = "gitlab" pluginName = "gitlab"
@ -37,11 +37,14 @@ defaultScopes = ["read_user"]
oauth2GitLab :: YesodAuth m => Text -> Text -> AuthPlugin m oauth2GitLab :: YesodAuth m => Text -> Text -> AuthPlugin m
oauth2GitLab = oauth2GitLabHostScopes defaultHost defaultScopes oauth2GitLab = oauth2GitLabHostScopes defaultHost defaultScopes
oauth2GitLabHostScopes :: YesodAuth m => URI -> [Text] -> Text -> Text -> AuthPlugin m oauth2GitLabHostScopes
:: YesodAuth m => URI -> [Text] -> Text -> Text -> AuthPlugin m
oauth2GitLabHostScopes host scopes clientId clientSecret = oauth2GitLabHostScopes host scopes clientId clientSecret =
authOAuth2 pluginName oauth2 $ \manager token -> do authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- authGetProfile pluginName manager token (User userId, userResponse) <-
$ host `withPath` "/api/v4/user" authGetProfile pluginName manager token
$ host
`withPath` "/api/v4/user"
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName
@ -52,9 +55,10 @@ oauth2GitLabHostScopes host scopes clientId clientSecret =
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = host , oauthOAuthorizeEndpoint =
host
`withPath` "/oauth/authorize" `withPath` "/oauth/authorize"
`withQuery` [ scopeParam " " scopes ] `withQuery` [scopeParam " " scopes]
, oauthAccessTokenEndpoint = host `withPath` "/oauth/token" , oauthAccessTokenEndpoint = host `withPath` "/oauth/token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -26,16 +26,18 @@
module Yesod.Auth.OAuth2.Google module Yesod.Auth.OAuth2.Google
( oauth2Google ( oauth2Google
, oauth2GoogleScoped , oauth2GoogleScoped
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
newtype User = User Text newtype User = User Text
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON =
withObject "User" $ \o -> User
-- Required for data backwards-compatibility -- Required for data backwards-compatibility
<$> (("google-uid:" <>) <$> o .: "sub") <$> (("google-uid:" <>) <$> o .: "sub")
pluginName :: Text pluginName :: Text
pluginName = "google" pluginName = "google"
@ -49,8 +51,11 @@ oauth2Google = oauth2GoogleScoped defaultScopes
oauth2GoogleScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m oauth2GoogleScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
oauth2GoogleScoped scopes clientId clientSecret = oauth2GoogleScoped scopes clientId clientSecret =
authOAuth2 pluginName oauth2 $ \manager token -> do authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- (User userId, userResponse) <- authGetProfile
authGetProfile pluginName manager token "https://www.googleapis.com/oauth2/v3/userinfo" pluginName
manager
token
"https://www.googleapis.com/oauth2/v3/userinfo"
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName
@ -61,9 +66,10 @@ oauth2GoogleScoped scopes clientId clientSecret =
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "https://accounts.google.com/o/oauth2/auth" `withQuery` , oauthOAuthorizeEndpoint =
[ scopeParam " " scopes "https://accounts.google.com/o/oauth2/auth"
] `withQuery` [scopeParam " " scopes]
, oauthAccessTokenEndpoint = "https://www.googleapis.com/oauth2/v3/token" , oauthAccessTokenEndpoint =
"https://www.googleapis.com/oauth2/v3/token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -2,7 +2,8 @@
module Yesod.Auth.OAuth2.Nylas module Yesod.Auth.OAuth2.Nylas
( oauth2Nylas ( oauth2Nylas
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -15,8 +16,7 @@ import qualified Yesod.Auth.OAuth2.Exception as YesodOAuth2Exception
newtype User = User Text newtype User = User Text
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "id"
<$> o .: "id"
pluginName :: Text pluginName :: Text
pluginName = "nylas" pluginName = "nylas"
@ -53,16 +53,17 @@ oauth2Nylas clientId clientSecret =
oauth = OAuth2 oauth = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "https://api.nylas.com/oauth/authorize" , oauthOAuthorizeEndpoint =
`withQuery` [ ("response_type", "code") "https://api.nylas.com/oauth/authorize"
, ( "client_id" `withQuery` [ ("response_type", "code")
, encodeUtf8 clientId , ( "client_id"
) , encodeUtf8 clientId
)
-- N.B. The scopes delimeter is unknown/untested. Verify that before -- N.B. The scopes delimeter is unknown/untested. Verify that before
-- extracting this to an argument and offering a Scoped function. In -- extracting this to an argument and offering a Scoped function. In
-- its current state, it doesn't matter because it's only one scope. -- its current state, it doesn't matter because it's only one scope.
, scopeParam "," defaultScopes , scopeParam "," defaultScopes
] ]
, oauthAccessTokenEndpoint = "https://api.nylas.com/oauth/token" , oauthAccessTokenEndpoint = "https://api.nylas.com/oauth/token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -11,15 +11,15 @@ module Yesod.Auth.OAuth2.Salesforce
, oauth2SalesforceScoped , oauth2SalesforceScoped
, oauth2SalesforceSandbox , oauth2SalesforceSandbox
, oauth2SalesforceSandboxScoped , oauth2SalesforceSandboxScoped
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
newtype User = User Text newtype User = User Text
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "user_id"
<$> o .: "user_id"
pluginName :: Text pluginName :: Text
pluginName = "salesforce" pluginName = "salesforce"
@ -31,7 +31,8 @@ oauth2Salesforce :: YesodAuth m => Text -> Text -> AuthPlugin m
oauth2Salesforce = oauth2SalesforceScoped defaultScopes oauth2Salesforce = oauth2SalesforceScoped defaultScopes
oauth2SalesforceScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m oauth2SalesforceScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
oauth2SalesforceScoped = salesforceHelper pluginName oauth2SalesforceScoped = salesforceHelper
pluginName
"https://login.salesforce.com/services/oauth2/userinfo" "https://login.salesforce.com/services/oauth2/userinfo"
"https://login.salesforce.com/services/oauth2/authorize" "https://login.salesforce.com/services/oauth2/authorize"
"https://login.salesforce.com/services/oauth2/token" "https://login.salesforce.com/services/oauth2/token"
@ -39,8 +40,10 @@ oauth2SalesforceScoped = salesforceHelper pluginName
oauth2SalesforceSandbox :: YesodAuth m => Text -> Text -> AuthPlugin m oauth2SalesforceSandbox :: YesodAuth m => Text -> Text -> AuthPlugin m
oauth2SalesforceSandbox = oauth2SalesforceSandboxScoped defaultScopes oauth2SalesforceSandbox = oauth2SalesforceSandboxScoped defaultScopes
oauth2SalesforceSandboxScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m oauth2SalesforceSandboxScoped
oauth2SalesforceSandboxScoped = salesforceHelper (pluginName <> "-sandbox") :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
oauth2SalesforceSandboxScoped = salesforceHelper
(pluginName <> "-sandbox")
"https://test.salesforce.com/services/oauth2/userinfo" "https://test.salesforce.com/services/oauth2/userinfo"
"https://test.salesforce.com/services/oauth2/authorize" "https://test.salesforce.com/services/oauth2/authorize"
"https://test.salesforce.com/services/oauth2/token" "https://test.salesforce.com/services/oauth2/token"
@ -55,9 +58,13 @@ salesforceHelper
-> Text -> Text
-> Text -> Text
-> AuthPlugin m -> AuthPlugin m
salesforceHelper name profileUri authorizeUri tokenUri scopes clientId clientSecret = salesforceHelper name profileUri authorizeUri tokenUri scopes clientId clientSecret
authOAuth2 name oauth2 $ \manager token -> do = authOAuth2 name oauth2 $ \manager token -> do
(User userId, userResponse) <- authGetProfile name manager token profileUri (User userId, userResponse) <- authGetProfile
name
manager
token
profileUri
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName
@ -68,7 +75,8 @@ salesforceHelper name profileUri authorizeUri tokenUri scopes clientId clientSec
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = authorizeUri `withQuery` [scopeParam " " scopes] , oauthOAuthorizeEndpoint =
authorizeUri `withQuery` [scopeParam " " scopes]
, oauthAccessTokenEndpoint = tokenUri , oauthAccessTokenEndpoint = tokenUri
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -9,7 +9,8 @@ module Yesod.Auth.OAuth2.Slack
( SlackScope(..) ( SlackScope(..)
, oauth2Slack , oauth2Slack
, oauth2SlackScoped , oauth2SlackScoped
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -66,8 +67,9 @@ oauth2SlackScoped scopes clientId clientSecret =
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "https://slack.com/oauth/authorize" , oauthOAuthorizeEndpoint =
`withQuery` [scopeParam "," $ map scopeText scopes] "https://slack.com/oauth/authorize"
`withQuery` [scopeParam "," $ map scopeText scopes]
, oauthAccessTokenEndpoint = "https://slack.com/api/oauth.access" , oauthAccessTokenEndpoint = "https://slack.com/api/oauth.access"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -5,15 +5,15 @@
-- --
module Yesod.Auth.OAuth2.Spotify module Yesod.Auth.OAuth2.Spotify
( oauth2Spotify ( oauth2Spotify
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
newtype User = User Text newtype User = User Text
instance FromJSON User where instance FromJSON User where
parseJSON = withObject "User" $ \o -> User parseJSON = withObject "User" $ \o -> User <$> o .: "id"
<$> o .: "id"
pluginName :: Text pluginName :: Text
pluginName = "spotify" pluginName = "spotify"
@ -21,8 +21,11 @@ pluginName = "spotify"
oauth2Spotify :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m oauth2Spotify :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
oauth2Spotify scopes clientId clientSecret = oauth2Spotify scopes clientId clientSecret =
authOAuth2 pluginName oauth2 $ \manager token -> do authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- (User userId, userResponse) <- authGetProfile
authGetProfile pluginName manager token "https://api.spotify.com/v1/me" pluginName
manager
token
"https://api.spotify.com/v1/me"
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName
@ -33,9 +36,9 @@ oauth2Spotify scopes clientId clientSecret =
oauth2 = OAuth2 oauth2 = OAuth2
{ oauthClientId = clientId { oauthClientId = clientId
, oauthClientSecret = clientSecret , oauthClientSecret = clientSecret
, oauthOAuthorizeEndpoint = "https://accounts.spotify.com/authorize" `withQuery` , oauthOAuthorizeEndpoint =
[ scopeParam " " scopes "https://accounts.spotify.com/authorize"
] `withQuery` [scopeParam " " scopes]
, oauthAccessTokenEndpoint = "https://accounts.spotify.com/api/token" , oauthAccessTokenEndpoint = "https://accounts.spotify.com/api/token"
, oauthCallback = Nothing , oauthCallback = Nothing
} }

View File

@ -8,7 +8,8 @@
-- --
module Yesod.Auth.OAuth2.Upcase module Yesod.Auth.OAuth2.Upcase
( oauth2Upcase ( oauth2Upcase
) where )
where
import Yesod.Auth.OAuth2.Prelude import Yesod.Auth.OAuth2.Prelude
@ -27,8 +28,11 @@ pluginName = "upcase"
oauth2Upcase :: YesodAuth m => Text -> Text -> AuthPlugin m oauth2Upcase :: YesodAuth m => Text -> Text -> AuthPlugin m
oauth2Upcase clientId clientSecret = oauth2Upcase clientId clientSecret =
authOAuth2 pluginName oauth2 $ \manager token -> do authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- (User userId, userResponse) <- authGetProfile
authGetProfile pluginName manager token "http://upcase.com/api/v1/me.json" pluginName
manager
token
"http://upcase.com/api/v1/me.json"
pure Creds pure Creds
{ credsPlugin = pluginName { credsPlugin = pluginName