mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-03-31 00:59:47 +02:00
Restyled by brittany
This commit is contained in:
parent
bd5df8e8a5
commit
e725cecf45
@ -6,20 +6,20 @@
|
|||||||
-- * Uses Auth0 user id (a.k.a [sub](https://auth0.com/docs/api/authentication#get-user-info)) as credentials identifier
|
-- * Uses Auth0 user id (a.k.a [sub](https://auth0.com/docs/api/authentication#get-user-info)) as credentials identifier
|
||||||
--
|
--
|
||||||
module Yesod.Auth.OAuth2.Auth0
|
module Yesod.Auth.OAuth2.Auth0
|
||||||
(oauth2Auth0HostScopes
|
( oauth2Auth0HostScopes
|
||||||
, defaultAuth0Scopes) where
|
, defaultAuth0Scopes
|
||||||
|
) where
|
||||||
|
|
||||||
import Data.Aeson as Aeson
|
import Data.Aeson as Aeson
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Prelude
|
||||||
import Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
-- | https://auth0.com/docs/api/authentication#get-user-info
|
-- | https://auth0.com/docs/api/authentication#get-user-info
|
||||||
newtype User = User T.Text
|
newtype User = User T.Text
|
||||||
|
|
||||||
instance FromJSON User where
|
instance FromJSON User where
|
||||||
parseJSON = withObject "User" $ \o ->
|
parseJSON = withObject "User" $ \o -> User <$> o .: "sub"
|
||||||
User <$> o .: "sub"
|
|
||||||
|
|
||||||
-- | https://auth0.com/docs/get-started/apis/scopes/openid-connect-scopes#standard-claims
|
-- | https://auth0.com/docs/get-started/apis/scopes/openid-connect-scopes#standard-claims
|
||||||
defaultAuth0Scopes :: [Text]
|
defaultAuth0Scopes :: [Text]
|
||||||
@ -28,26 +28,25 @@ defaultAuth0Scopes = ["openid"]
|
|||||||
pluginName :: Text
|
pluginName :: Text
|
||||||
pluginName = "auth0"
|
pluginName = "auth0"
|
||||||
|
|
||||||
oauth2Auth0HostScopes :: YesodAuth m => URI -> [Text] -> Text -> Text -> AuthPlugin m
|
oauth2Auth0HostScopes
|
||||||
|
:: YesodAuth m => URI -> [Text] -> Text -> Text -> AuthPlugin m
|
||||||
oauth2Auth0HostScopes host scopes clientId clientSecret =
|
oauth2Auth0HostScopes host scopes clientId clientSecret =
|
||||||
authOAuth2 pluginName oauth2 $ \manager token -> do
|
authOAuth2 pluginName oauth2 $ \manager token -> do
|
||||||
(User uid, userResponse) <-
|
(User uid, userResponse) <- authGetProfile pluginName
|
||||||
authGetProfile pluginName manager token (host `withPath` "/userinfo")
|
manager
|
||||||
pure
|
token
|
||||||
Creds
|
(host `withPath` "/userinfo")
|
||||||
{ credsPlugin = pluginName,
|
pure Creds { credsPlugin = pluginName
|
||||||
credsIdent = uid,
|
, credsIdent = uid
|
||||||
credsExtra = setExtra token userResponse
|
, credsExtra = setExtra token userResponse
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
oauth2 =
|
oauth2 = OAuth2
|
||||||
OAuth2
|
{ oauth2ClientId = clientId
|
||||||
{ oauth2ClientId = clientId,
|
, oauth2ClientSecret = Just clientSecret
|
||||||
oauth2ClientSecret = Just clientSecret,
|
, oauth2AuthorizeEndpoint = host
|
||||||
oauth2AuthorizeEndpoint =
|
`withPath` "/authorize"
|
||||||
host
|
`withQuery` [scopeParam " " scopes]
|
||||||
`withPath` "/authorize"
|
, oauth2TokenEndpoint = host `withPath` "/oauth/token"
|
||||||
`withQuery` [scopeParam " " scopes],
|
, oauth2RedirectUri = Nothing
|
||||||
oauth2TokenEndpoint = host `withPath` "/oauth/token",
|
}
|
||||||
oauth2RedirectUri = Nothing
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user