From e725cecf458138d933ab0975ebacec002e2bb69c Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 17 Aug 2022 19:42:19 +0000 Subject: [PATCH] Restyled by brittany --- src/Yesod/Auth/OAuth2/Auth0.hs | 57 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/Yesod/Auth/OAuth2/Auth0.hs b/src/Yesod/Auth/OAuth2/Auth0.hs index dc6af7c..0fbe68e 100644 --- a/src/Yesod/Auth/OAuth2/Auth0.hs +++ b/src/Yesod/Auth/OAuth2/Auth0.hs @@ -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 + }