mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-09-11 03:44:57 +02:00
Restyled by brittany
This commit is contained in:
parent
0d8b1b0ecc
commit
23b73d590d
@ -28,13 +28,17 @@ module Yesod.Auth.OAuth2
|
|||||||
, getUserResponseJSON
|
, getUserResponseJSON
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Error.Util (note)
|
import Control.Error.Util ( note )
|
||||||
import Control.Monad ((<=<))
|
import Control.Monad ( (<=<) )
|
||||||
import Data.Aeson (FromJSON, eitherDecode)
|
import Data.Aeson ( FromJSON
|
||||||
import Data.ByteString.Lazy (ByteString, fromStrict)
|
, eitherDecode
|
||||||
import Data.Text (Text)
|
)
|
||||||
import Data.Text.Encoding (encodeUtf8)
|
import Data.ByteString.Lazy ( ByteString
|
||||||
import Network.HTTP.Conduit (Manager)
|
, fromStrict
|
||||||
|
)
|
||||||
|
import Data.Text ( Text )
|
||||||
|
import Data.Text.Encoding ( encodeUtf8 )
|
||||||
|
import Network.HTTP.Conduit ( Manager )
|
||||||
import Network.OAuth.OAuth2.Compat
|
import Network.OAuth.OAuth2.Compat
|
||||||
import Yesod.Auth
|
import Yesod.Auth
|
||||||
import Yesod.Auth.OAuth2.Dispatch
|
import Yesod.Auth.OAuth2.Dispatch
|
||||||
|
|||||||
@ -9,8 +9,7 @@
|
|||||||
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
|
||||||
@ -38,8 +37,7 @@ oauth2AzureADScoped scopes clientId clientSecret =
|
|||||||
token
|
token
|
||||||
"https://graph.microsoft.com/v1.0/me"
|
"https://graph.microsoft.com/v1.0/me"
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = userId
|
, credsIdent = userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -52,7 +50,6 @@ oauth2AzureADScoped scopes clientId clientSecret =
|
|||||||
`withQuery` [ scopeParam "," scopes
|
`withQuery` [ scopeParam "," scopes
|
||||||
, ("resource", "https://graph.microsoft.com")
|
, ("resource", "https://graph.microsoft.com")
|
||||||
]
|
]
|
||||||
, oauth2TokenEndpoint =
|
, oauth2TokenEndpoint = "https://login.windows.net/common/oauth2/token"
|
||||||
"https://login.windows.net/common/oauth2/token"
|
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,12 +11,14 @@
|
|||||||
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
|
||||||
|
|
||||||
import qualified Data.Text as T (pack, toLower)
|
import qualified Data.Text as T
|
||||||
|
( pack
|
||||||
|
, toLower
|
||||||
|
)
|
||||||
import Yesod.Core.Widget
|
import Yesod.Core.Widget
|
||||||
|
|
||||||
newtype User = User Int
|
newtype User = User Int
|
||||||
@ -38,13 +40,9 @@ 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
|
$ fromRelative "https" (apiHost $ T.toLower region) "/account/user"
|
||||||
"https"
|
|
||||||
(apiHost $ T.toLower region)
|
|
||||||
"/account/user"
|
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = T.pack $ show userId
|
, credsIdent = T.pack $ show userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,7 @@
|
|||||||
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
|
||||||
|
|
||||||
@ -39,8 +38,7 @@ oauth2BitbucketScoped scopes clientId clientSecret =
|
|||||||
token
|
token
|
||||||
"https://api.bitbucket.com/2.0/user"
|
"https://api.bitbucket.com/2.0/user"
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
-- FIXME: Preserved bug. This should just be userId (it's already
|
-- FIXME: Preserved bug. This should just be userId (it's already
|
||||||
-- a Text), but because this code was shipped, folks likely have
|
-- a Text), but because this code was shipped, folks likely have
|
||||||
-- Idents in their database like @"\"...\""@, and if we fixed this
|
-- Idents in their database like @"\"...\""@, and if we fixed this
|
||||||
@ -54,10 +52,8 @@ oauth2BitbucketScoped scopes clientId clientSecret =
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = "https://bitbucket.com/site/oauth2/authorize"
|
||||||
"https://bitbucket.com/site/oauth2/authorize"
|
|
||||||
`withQuery` [scopeParam "," scopes]
|
`withQuery` [scopeParam "," scopes]
|
||||||
, oauth2TokenEndpoint =
|
, oauth2TokenEndpoint = "https://bitbucket.com/site/oauth2/access_token"
|
||||||
"https://bitbucket.com/site/oauth2/access_token"
|
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,7 @@
|
|||||||
module Yesod.Auth.OAuth2.ClassLink
|
module Yesod.Auth.OAuth2.ClassLink
|
||||||
( oauth2ClassLink
|
( oauth2ClassLink
|
||||||
, oauth2ClassLinkScoped
|
, oauth2ClassLinkScoped
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
@ -33,8 +32,7 @@ oauth2ClassLinkScoped scopes clientId clientSecret =
|
|||||||
token
|
token
|
||||||
"https://nodeapi.classlink.com/v2/my/info"
|
"https://nodeapi.classlink.com/v2/my/info"
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = T.pack $ show userId
|
, credsIdent = T.pack $ show userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -42,10 +40,8 @@ oauth2ClassLinkScoped scopes clientId clientSecret =
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = "https://launchpad.classlink.com/oauth2/v2/auth"
|
||||||
"https://launchpad.classlink.com/oauth2/v2/auth"
|
|
||||||
`withQuery` [scopeParam "," scopes]
|
`withQuery` [scopeParam "," scopes]
|
||||||
, oauth2TokenEndpoint =
|
, oauth2TokenEndpoint = "https://launchpad.classlink.com/oauth2/v2/token"
|
||||||
"https://launchpad.classlink.com/oauth2/v2/token"
|
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,19 +13,20 @@ module Yesod.Auth.OAuth2.Dispatch
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Except
|
import Control.Monad.Except
|
||||||
import Data.Text (Text)
|
import Data.Text ( Text )
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Text.Encoding (encodeUtf8)
|
import Data.Text.Encoding ( encodeUtf8 )
|
||||||
import Network.HTTP.Conduit (Manager)
|
import Network.HTTP.Conduit ( Manager )
|
||||||
import Network.OAuth.OAuth2.Compat
|
import Network.OAuth.OAuth2.Compat
|
||||||
import Network.OAuth.OAuth2.TokenRequest (Errors)
|
import Network.OAuth.OAuth2.TokenRequest
|
||||||
|
( Errors )
|
||||||
import URI.ByteString.Extension
|
import URI.ByteString.Extension
|
||||||
import UnliftIO.Exception
|
import UnliftIO.Exception
|
||||||
import Yesod.Auth hiding (ServerError)
|
import Yesod.Auth hiding ( ServerError )
|
||||||
import Yesod.Auth.OAuth2.DispatchError
|
import Yesod.Auth.OAuth2.DispatchError
|
||||||
import Yesod.Auth.OAuth2.ErrorResponse
|
import Yesod.Auth.OAuth2.ErrorResponse
|
||||||
import Yesod.Auth.OAuth2.Random
|
import Yesod.Auth.OAuth2.Random
|
||||||
import Yesod.Core hiding (ErrorResponse)
|
import Yesod.Core hiding ( ErrorResponse )
|
||||||
|
|
||||||
-- | How to fetch an @'OAuth2Token'@
|
-- | How to fetch an @'OAuth2Token'@
|
||||||
--
|
--
|
||||||
@ -105,8 +106,7 @@ withCallbackAndState name oauth2 csrf = do
|
|||||||
callback <- maybe (throwError $ InvalidCallbackUri uri) pure $ fromText uri
|
callback <- maybe (throwError $ InvalidCallbackUri uri) pure $ fromText uri
|
||||||
pure oauth2
|
pure oauth2
|
||||||
{ oauth2RedirectUri = Just callback
|
{ oauth2RedirectUri = Just callback
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = oauth2AuthorizeEndpoint oauth2
|
||||||
oauth2AuthorizeEndpoint oauth2
|
|
||||||
`withQuery` [("state", encodeUtf8 csrf)]
|
`withQuery` [("state", encodeUtf8 csrf)]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,8 +135,7 @@ verifySessionCSRF sessionKey = do
|
|||||||
token <- requireGetParam "state"
|
token <- requireGetParam "state"
|
||||||
sessionToken <- lookupSession sessionKey
|
sessionToken <- lookupSession sessionKey
|
||||||
deleteSession sessionKey
|
deleteSession sessionKey
|
||||||
token <$ unless
|
token <$ unless (sessionToken == Just token)
|
||||||
(sessionToken == Just token)
|
|
||||||
(throwError $ InvalidStateToken sessionToken token)
|
(throwError $ InvalidStateToken sessionToken token)
|
||||||
|
|
||||||
requireGetParam
|
requireGetParam
|
||||||
|
|||||||
@ -11,8 +11,7 @@ module Yesod.Auth.OAuth2.EveOnline
|
|||||||
( oauth2Eve
|
( oauth2Eve
|
||||||
, oauth2EveScoped
|
, oauth2EveScoped
|
||||||
, WidgetType(..)
|
, WidgetType(..)
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
@ -56,16 +55,15 @@ oauth2Eve = oauth2EveScoped defaultScopes
|
|||||||
oauth2EveScoped
|
oauth2EveScoped
|
||||||
:: YesodAuth m => [Text] -> WidgetType m -> Text -> Text -> AuthPlugin m
|
:: YesodAuth m => [Text] -> WidgetType m -> Text -> Text -> AuthPlugin m
|
||||||
oauth2EveScoped scopes widgetType clientId clientSecret =
|
oauth2EveScoped scopes widgetType clientId clientSecret =
|
||||||
authOAuth2Widget (asWidget widgetType) pluginName oauth2
|
authOAuth2Widget (asWidget widgetType) pluginName oauth2 $ \manager token ->
|
||||||
$ \manager token -> do
|
do
|
||||||
(User userId, userResponse) <- authGetProfile
|
(User userId, userResponse) <- authGetProfile
|
||||||
pluginName
|
pluginName
|
||||||
manager
|
manager
|
||||||
token
|
token
|
||||||
"https://login.eveonline.com/oauth/verify"
|
"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
|
||||||
@ -74,9 +72,10 @@ oauth2EveScoped scopes widgetType clientId clientSecret =
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = "https://login.eveonline.com/oauth/authorize"
|
||||||
"https://login.eveonline.com/oauth/authorize"
|
`withQuery` [ ("response_type", "code")
|
||||||
`withQuery` [("response_type", "code"), scopeParam " " scopes]
|
, scopeParam " " scopes
|
||||||
|
]
|
||||||
, oauth2TokenEndpoint = "https://login.eveonline.com/oauth/token"
|
, oauth2TokenEndpoint = "https://login.eveonline.com/oauth/token"
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,8 +9,7 @@
|
|||||||
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
|
||||||
|
|
||||||
@ -39,8 +38,7 @@ oauth2GitHubScoped scopes clientId clientSecret =
|
|||||||
token
|
token
|
||||||
"https://api.github.com/user"
|
"https://api.github.com/user"
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = T.pack $ show userId
|
, credsIdent = T.pack $ show userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -48,10 +46,8 @@ oauth2GitHubScoped scopes clientId clientSecret =
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = "https://github.com/login/oauth/authorize"
|
||||||
"https://github.com/login/oauth/authorize"
|
|
||||||
`withQuery` [scopeParam "," scopes]
|
`withQuery` [scopeParam "," scopes]
|
||||||
, oauth2TokenEndpoint =
|
, oauth2TokenEndpoint = "https://github.com/login/oauth/access_token"
|
||||||
"https://github.com/login/oauth/access_token"
|
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,8 +4,7 @@ module Yesod.Auth.OAuth2.GitLab
|
|||||||
, oauth2GitLabHostScopes
|
, oauth2GitLabHostScopes
|
||||||
, defaultHost
|
, defaultHost
|
||||||
, defaultScopes
|
, defaultScopes
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
@ -42,12 +41,9 @@ oauth2GitLabHostScopes
|
|||||||
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) <-
|
(User userId, userResponse) <-
|
||||||
authGetProfile pluginName manager token
|
authGetProfile pluginName manager token $ host `withPath` "/api/v4/user"
|
||||||
$ host
|
|
||||||
`withPath` "/api/v4/user"
|
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = T.pack $ show userId
|
, credsIdent = T.pack $ show userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -55,8 +51,7 @@ oauth2GitLabHostScopes host scopes clientId clientSecret =
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = host
|
||||||
host
|
|
||||||
`withPath` "/oauth/authorize"
|
`withPath` "/oauth/authorize"
|
||||||
`withQuery` [scopeParam " " scopes]
|
`withQuery` [scopeParam " " scopes]
|
||||||
, oauth2TokenEndpoint = host `withPath` "/oauth/token"
|
, oauth2TokenEndpoint = host `withPath` "/oauth/token"
|
||||||
|
|||||||
@ -29,11 +29,12 @@ module Yesod.Auth.OAuth2.Google
|
|||||||
, oauth2GoogleWidget
|
, oauth2GoogleWidget
|
||||||
, oauth2GoogleScoped
|
, oauth2GoogleScoped
|
||||||
, oauth2GoogleScopedWidget
|
, oauth2GoogleScopedWidget
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
import Yesod.Core (WidgetFor, whamlet)
|
import Yesod.Core ( WidgetFor
|
||||||
|
, whamlet
|
||||||
|
)
|
||||||
|
|
||||||
newtype User = User Text
|
newtype User = User Text
|
||||||
|
|
||||||
@ -52,13 +53,16 @@ defaultScopes = ["openid", "email"]
|
|||||||
oauth2Google :: YesodAuth m => Text -> Text -> AuthPlugin m
|
oauth2Google :: YesodAuth m => Text -> Text -> AuthPlugin m
|
||||||
oauth2Google = oauth2GoogleScoped defaultScopes
|
oauth2Google = oauth2GoogleScoped defaultScopes
|
||||||
|
|
||||||
oauth2GoogleWidget :: YesodAuth m => WidgetFor m () -> Text -> Text -> AuthPlugin m
|
oauth2GoogleWidget
|
||||||
|
:: YesodAuth m => WidgetFor m () -> Text -> Text -> AuthPlugin m
|
||||||
oauth2GoogleWidget widget = oauth2GoogleScopedWidget widget defaultScopes
|
oauth2GoogleWidget widget = oauth2GoogleScopedWidget widget defaultScopes
|
||||||
|
|
||||||
oauth2GoogleScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
|
oauth2GoogleScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
|
||||||
oauth2GoogleScoped = oauth2GoogleScopedWidget [whamlet|Login via #{pluginName}|]
|
oauth2GoogleScoped =
|
||||||
|
oauth2GoogleScopedWidget [whamlet|Login via #{pluginName}|]
|
||||||
|
|
||||||
oauth2GoogleScopedWidget :: YesodAuth m => WidgetFor m () -> [Text] -> Text -> Text -> AuthPlugin m
|
oauth2GoogleScopedWidget
|
||||||
|
:: YesodAuth m => WidgetFor m () -> [Text] -> Text -> Text -> AuthPlugin m
|
||||||
oauth2GoogleScopedWidget widget scopes clientId clientSecret =
|
oauth2GoogleScopedWidget widget scopes clientId clientSecret =
|
||||||
authOAuth2Widget widget pluginName oauth2 $ \manager token -> do
|
authOAuth2Widget widget pluginName oauth2 $ \manager token -> do
|
||||||
(User userId, userResponse) <- authGetProfile
|
(User userId, userResponse) <- authGetProfile
|
||||||
@ -67,8 +71,7 @@ oauth2GoogleScopedWidget widget scopes clientId clientSecret =
|
|||||||
token
|
token
|
||||||
"https://www.googleapis.com/oauth2/v3/userinfo"
|
"https://www.googleapis.com/oauth2/v3/userinfo"
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = userId
|
, credsIdent = userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -76,10 +79,8 @@ oauth2GoogleScopedWidget widget scopes clientId clientSecret =
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = "https://accounts.google.com/o/oauth2/auth"
|
||||||
"https://accounts.google.com/o/oauth2/auth"
|
|
||||||
`withQuery` [scopeParam " " scopes]
|
`withQuery` [scopeParam " " scopes]
|
||||||
, oauth2TokenEndpoint =
|
, oauth2TokenEndpoint = "https://www.googleapis.com/oauth2/v3/token"
|
||||||
"https://www.googleapis.com/oauth2/v3/token"
|
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,12 +2,11 @@
|
|||||||
|
|
||||||
module Yesod.Auth.OAuth2.Nylas
|
module Yesod.Auth.OAuth2.Nylas
|
||||||
( oauth2Nylas
|
( oauth2Nylas
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
import Control.Monad (unless)
|
import Control.Monad ( unless )
|
||||||
import qualified Data.ByteString.Lazy.Char8 as BL8
|
import qualified Data.ByteString.Lazy.Char8 as BL8
|
||||||
import Network.HTTP.Client
|
import Network.HTTP.Client
|
||||||
import qualified Network.HTTP.Types as HT
|
import qualified Network.HTTP.Types as HT
|
||||||
@ -42,8 +41,7 @@ oauth2Nylas clientId clientSecret =
|
|||||||
|
|
||||||
either
|
either
|
||||||
(throwIO . YesodOAuth2Exception.JSONDecodingError pluginName)
|
(throwIO . YesodOAuth2Exception.JSONDecodingError pluginName)
|
||||||
(\(User userId) -> pure Creds
|
(\(User userId) -> pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = userId
|
, credsIdent = userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -53,8 +51,7 @@ oauth2Nylas clientId clientSecret =
|
|||||||
oauth = OAuth2
|
oauth = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = "https://api.nylas.com/oauth/authorize"
|
||||||
"https://api.nylas.com/oauth/authorize"
|
|
||||||
`withQuery` [ ("response_type", "code")
|
`withQuery` [ ("response_type", "code")
|
||||||
, ( "client_id"
|
, ( "client_id"
|
||||||
, encodeUtf8 clientId
|
, encodeUtf8 clientId
|
||||||
|
|||||||
@ -58,9 +58,9 @@ module Yesod.Auth.OAuth2.Prelude
|
|||||||
|
|
||||||
import Control.Exception.Safe
|
import Control.Exception.Safe
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString ( ByteString )
|
||||||
import qualified Data.ByteString.Lazy as BL
|
import qualified Data.ByteString.Lazy as BL
|
||||||
import Data.Text (Text)
|
import Data.Text ( Text )
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Text.Encoding
|
import Data.Text.Encoding
|
||||||
import Network.HTTP.Conduit
|
import Network.HTTP.Conduit
|
||||||
|
|||||||
@ -11,8 +11,7 @@ module Yesod.Auth.OAuth2.Salesforce
|
|||||||
, oauth2SalesforceScoped
|
, oauth2SalesforceScoped
|
||||||
, oauth2SalesforceSandbox
|
, oauth2SalesforceSandbox
|
||||||
, oauth2SalesforceSandboxScoped
|
, oauth2SalesforceSandboxScoped
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
@ -60,14 +59,9 @@ salesforceHelper
|
|||||||
-> 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
|
(User userId, userResponse) <- authGetProfile name manager token profileUri
|
||||||
name
|
|
||||||
manager
|
|
||||||
token
|
|
||||||
profileUri
|
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = userId
|
, credsIdent = userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -75,8 +69,7 @@ salesforceHelper name profileUri authorizeUri tokenUri scopes clientId clientSec
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = authorizeUri `withQuery` [scopeParam " " scopes]
|
||||||
authorizeUri `withQuery` [scopeParam " " scopes]
|
|
||||||
, oauth2TokenEndpoint = tokenUri
|
, oauth2TokenEndpoint = tokenUri
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,13 +9,15 @@ module Yesod.Auth.OAuth2.Slack
|
|||||||
( SlackScope(..)
|
( SlackScope(..)
|
||||||
, oauth2Slack
|
, oauth2Slack
|
||||||
, oauth2SlackScoped
|
, oauth2SlackScoped
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
import Network.HTTP.Client
|
import Network.HTTP.Client ( httpLbs
|
||||||
(httpLbs, parseUrlThrow, responseBody, setQueryString)
|
, parseUrlThrow
|
||||||
|
, responseBody
|
||||||
|
, setQueryString
|
||||||
|
)
|
||||||
import Yesod.Auth.OAuth2.Exception as YesodOAuth2Exception
|
import Yesod.Auth.OAuth2.Exception as YesodOAuth2Exception
|
||||||
|
|
||||||
data SlackScope
|
data SlackScope
|
||||||
@ -46,7 +48,8 @@ defaultScopes = [SlackBasicScope]
|
|||||||
oauth2Slack :: YesodAuth m => Text -> Text -> AuthPlugin m
|
oauth2Slack :: YesodAuth m => Text -> Text -> AuthPlugin m
|
||||||
oauth2Slack = oauth2SlackScoped defaultScopes
|
oauth2Slack = oauth2SlackScoped defaultScopes
|
||||||
|
|
||||||
oauth2SlackScoped :: YesodAuth m => [SlackScope] -> Text -> Text -> AuthPlugin m
|
oauth2SlackScoped
|
||||||
|
:: YesodAuth m => [SlackScope] -> Text -> Text -> AuthPlugin m
|
||||||
oauth2SlackScoped scopes clientId clientSecret =
|
oauth2SlackScoped scopes clientId clientSecret =
|
||||||
authOAuth2 pluginName oauth2 $ \manager token -> do
|
authOAuth2 pluginName oauth2 $ \manager token -> do
|
||||||
let param = encodeUtf8 $ atoken $ accessToken token
|
let param = encodeUtf8 $ atoken $ accessToken token
|
||||||
@ -56,8 +59,7 @@ oauth2SlackScoped scopes clientId clientSecret =
|
|||||||
|
|
||||||
either
|
either
|
||||||
(throwIO . YesodOAuth2Exception.JSONDecodingError pluginName)
|
(throwIO . YesodOAuth2Exception.JSONDecodingError pluginName)
|
||||||
(\(User userId) -> pure Creds
|
(\(User userId) -> pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = userId
|
, credsIdent = userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -67,9 +69,10 @@ oauth2SlackScoped scopes clientId clientSecret =
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = "https://slack.com/oauth/authorize"
|
||||||
"https://slack.com/oauth/authorize"
|
`withQuery` [ scopeParam ","
|
||||||
`withQuery` [scopeParam "," $ map scopeText scopes]
|
$ map scopeText scopes
|
||||||
|
]
|
||||||
, oauth2TokenEndpoint = "https://slack.com/api/oauth.access"
|
, oauth2TokenEndpoint = "https://slack.com/api/oauth.access"
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,8 +5,7 @@
|
|||||||
--
|
--
|
||||||
module Yesod.Auth.OAuth2.Spotify
|
module Yesod.Auth.OAuth2.Spotify
|
||||||
( oauth2Spotify
|
( oauth2Spotify
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
@ -27,8 +26,7 @@ oauth2Spotify scopes clientId clientSecret =
|
|||||||
token
|
token
|
||||||
"https://api.spotify.com/v1/me"
|
"https://api.spotify.com/v1/me"
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = userId
|
, credsIdent = userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -36,8 +34,7 @@ oauth2Spotify scopes clientId clientSecret =
|
|||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint = "https://accounts.spotify.com/authorize"
|
||||||
"https://accounts.spotify.com/authorize"
|
|
||||||
`withQuery` [scopeParam " " scopes]
|
`withQuery` [scopeParam " " scopes]
|
||||||
, oauth2TokenEndpoint = "https://accounts.spotify.com/api/token"
|
, oauth2TokenEndpoint = "https://accounts.spotify.com/api/token"
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
|
|||||||
@ -8,8 +8,7 @@
|
|||||||
--
|
--
|
||||||
module Yesod.Auth.OAuth2.Upcase
|
module Yesod.Auth.OAuth2.Upcase
|
||||||
( oauth2Upcase
|
( oauth2Upcase
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
@ -34,8 +33,7 @@ oauth2Upcase clientId clientSecret =
|
|||||||
token
|
token
|
||||||
"http://upcase.com/api/v1/me.json"
|
"http://upcase.com/api/v1/me.json"
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = T.pack $ show userId
|
, credsIdent = T.pack $ show userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
module Yesod.Auth.OAuth2.WordPressDotCom
|
module Yesod.Auth.OAuth2.WordPressDotCom
|
||||||
( oauth2WordPressDotCom
|
( oauth2WordPressDotCom
|
||||||
)
|
) where
|
||||||
where
|
|
||||||
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
@ -29,8 +28,7 @@ oauth2WordPressDotCom clientId clientSecret =
|
|||||||
token
|
token
|
||||||
"https://public-api.wordpress.com/rest/v1/me/"
|
"https://public-api.wordpress.com/rest/v1/me/"
|
||||||
|
|
||||||
pure Creds
|
pure Creds { credsPlugin = pluginName
|
||||||
{ credsPlugin = pluginName
|
|
||||||
, credsIdent = T.pack $ show userId
|
, credsIdent = T.pack $ show userId
|
||||||
, credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
@ -42,7 +40,6 @@ oauth2WordPressDotCom clientId clientSecret =
|
|||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint =
|
||||||
"https://public-api.wordpress.com/oauth2/authorize"
|
"https://public-api.wordpress.com/oauth2/authorize"
|
||||||
`withQuery` [scopeParam "," ["auth"]]
|
`withQuery` [scopeParam "," ["auth"]]
|
||||||
, oauth2TokenEndpoint =
|
, oauth2TokenEndpoint = "https://public-api.wordpress.com/oauth2/token"
|
||||||
"https://public-api.wordpress.com/oauth2/token"
|
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user