Restyled by brittany

This commit is contained in:
Restyled.io 2022-08-17 19:42:19 +00:00 committed by patrick brisbin
parent bd5df8e8a5
commit e725cecf45

View File

@ -6,20 +6,20 @@
-- * 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
(oauth2Auth0HostScopes
, defaultAuth0Scopes) where
( oauth2Auth0HostScopes
, defaultAuth0Scopes
) where
import Data.Aeson as Aeson
import qualified Data.Text as T
import Yesod.Auth.OAuth2.Prelude
import Prelude
import Data.Aeson as Aeson
import qualified Data.Text as T
import Prelude
import Yesod.Auth.OAuth2.Prelude
-- | https://auth0.com/docs/api/authentication#get-user-info
newtype User = User T.Text
instance FromJSON User where
parseJSON = withObject "User" $ \o ->
User <$> o .: "sub"
parseJSON = withObject "User" $ \o -> User <$> o .: "sub"
-- | https://auth0.com/docs/get-started/apis/scopes/openid-connect-scopes#standard-claims
defaultAuth0Scopes :: [Text]
@ -28,26 +28,25 @@ defaultAuth0Scopes = ["openid"]
pluginName :: Text
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 =
authOAuth2 pluginName oauth2 $ \manager token -> do
(User uid, userResponse) <-
authGetProfile pluginName manager token (host `withPath` "/userinfo")
pure
Creds
{ credsPlugin = pluginName,
credsIdent = uid,
credsExtra = setExtra token userResponse
}
where
oauth2 =
OAuth2
{ oauth2ClientId = clientId,
oauth2ClientSecret = Just clientSecret,
oauth2AuthorizeEndpoint =
host
`withPath` "/authorize"
`withQuery` [scopeParam " " scopes],
oauth2TokenEndpoint = host `withPath` "/oauth/token",
oauth2RedirectUri = Nothing
}
(User uid, userResponse) <- authGetProfile pluginName
manager
token
(host `withPath` "/userinfo")
pure Creds { credsPlugin = pluginName
, credsIdent = uid
, credsExtra = setExtra token userResponse
}
where
oauth2 = OAuth2
{ oauth2ClientId = clientId
, oauth2ClientSecret = Just clientSecret
, oauth2AuthorizeEndpoint = host
`withPath` "/authorize"
`withQuery` [scopeParam " " scopes]
, oauth2TokenEndpoint = host `withPath` "/oauth/token"
, oauth2RedirectUri = Nothing
}