Restyled by brittany

This commit is contained in:
Restyled.io 2023-04-06 12:44:43 +00:00 committed by Pat Brisbin
parent 1e68d6b02c
commit fb1b506606

View File

@ -7,9 +7,9 @@
-- * Uses email as credentials identifier
--
module Yesod.Auth.OAuth2.AzureADv2
( oauth2AzureADv2
, oauth2AzureADv2Scoped
) where
( oauth2AzureADv2
, oauth2AzureADv2Scoped
) where
import Prelude
import Yesod.Auth.OAuth2.Prelude
@ -20,7 +20,7 @@ import Data.Text (unpack)
newtype User = User Text
instance FromJSON User where
parseJSON = withObject "User" $ \o -> User <$> o .: "mail"
parseJSON = withObject "User" $ \o -> User <$> o .: "mail"
pluginName :: Text
pluginName = "azureadv2"
@ -29,54 +29,54 @@ defaultScopes :: [Text]
defaultScopes = ["openid", "profile"]
oauth2AzureADv2
:: YesodAuth m
=> Text
:: YesodAuth m
=> Text
-- ^ Tenant Id
--
-- If using a multi-tenant App, @common@ can be given here.
--
-> Text -- ^ Client Id
-> Text -- ^ Client secret
-> AuthPlugin m
-> Text -- ^ Client Id
-> Text -- ^ Client secret
-> AuthPlugin m
oauth2AzureADv2 = oauth2AzureADv2Scoped defaultScopes
oauth2AzureADv2Scoped
:: YesodAuth m
=> [Text] -- ^ Scopes
-> Text
:: YesodAuth m
=> [Text] -- ^ Scopes
-> Text
-- ^ Tenant Id
--
-- If using a multi-tenant App, @common@ can be given here.
--
-> Text -- ^ Client Id
-> Text -- ^ Client Secret
-> AuthPlugin m
-> Text -- ^ Client Id
-> Text -- ^ Client Secret
-> AuthPlugin m
oauth2AzureADv2Scoped scopes tenantId clientId clientSecret =
authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- authGetProfile
pluginName
manager
token
"https://graph.microsoft.com/v1.0/me"
authOAuth2 pluginName oauth2 $ \manager token -> do
(User userId, userResponse) <- authGetProfile
pluginName
manager
token
"https://graph.microsoft.com/v1.0/me"
pure Creds
{ credsPlugin = pluginName
, credsIdent = userId
, credsExtra = setExtra token userResponse
}
where
oauth2 = OAuth2
{ oauth2ClientId = clientId
, oauth2ClientSecret = Just clientSecret
, oauth2AuthorizeEndpoint =
tenantUrl "/authorize" `withQuery` [scopeParam " " scopes]
, oauth2TokenEndpoint = tenantUrl "/token"
, oauth2RedirectUri = Nothing
}
pure Creds
{ credsPlugin = pluginName
, credsIdent = userId
, credsExtra = setExtra token userResponse
}
where
oauth2 = OAuth2
{ oauth2ClientId = clientId
, oauth2ClientSecret = Just clientSecret
, oauth2AuthorizeEndpoint =
tenantUrl "/authorize" `withQuery` [scopeParam " " scopes]
, oauth2TokenEndpoint = tenantUrl "/token"
, oauth2RedirectUri = Nothing
}
tenantUrl path =
fromString
$ "https://login.microsoftonline.com/"
<> unpack tenantId
<> "/oauth2/v2.0"
<> path
tenantUrl path =
fromString
$ "https://login.microsoftonline.com/"
<> unpack tenantId
<> "/oauth2/v2.0"
<> path