mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-04-21 10:17:43 +02:00
Restyled by brittany
This commit is contained in:
parent
1e68d6b02c
commit
fb1b506606
@ -7,9 +7,9 @@
|
|||||||
-- * Uses email as credentials identifier
|
-- * Uses email as credentials identifier
|
||||||
--
|
--
|
||||||
module Yesod.Auth.OAuth2.AzureADv2
|
module Yesod.Auth.OAuth2.AzureADv2
|
||||||
( oauth2AzureADv2
|
( oauth2AzureADv2
|
||||||
, oauth2AzureADv2Scoped
|
, oauth2AzureADv2Scoped
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
@ -20,7 +20,7 @@ import Data.Text (unpack)
|
|||||||
newtype User = User Text
|
newtype User = User Text
|
||||||
|
|
||||||
instance FromJSON User where
|
instance FromJSON User where
|
||||||
parseJSON = withObject "User" $ \o -> User <$> o .: "mail"
|
parseJSON = withObject "User" $ \o -> User <$> o .: "mail"
|
||||||
|
|
||||||
pluginName :: Text
|
pluginName :: Text
|
||||||
pluginName = "azureadv2"
|
pluginName = "azureadv2"
|
||||||
@ -29,54 +29,54 @@ defaultScopes :: [Text]
|
|||||||
defaultScopes = ["openid", "profile"]
|
defaultScopes = ["openid", "profile"]
|
||||||
|
|
||||||
oauth2AzureADv2
|
oauth2AzureADv2
|
||||||
:: YesodAuth m
|
:: YesodAuth m
|
||||||
=> Text
|
=> Text
|
||||||
-- ^ Tenant Id
|
-- ^ Tenant Id
|
||||||
--
|
--
|
||||||
-- If using a multi-tenant App, @common@ can be given here.
|
-- If using a multi-tenant App, @common@ can be given here.
|
||||||
--
|
--
|
||||||
-> Text -- ^ Client Id
|
-> Text -- ^ Client Id
|
||||||
-> Text -- ^ Client secret
|
-> Text -- ^ Client secret
|
||||||
-> AuthPlugin m
|
-> AuthPlugin m
|
||||||
oauth2AzureADv2 = oauth2AzureADv2Scoped defaultScopes
|
oauth2AzureADv2 = oauth2AzureADv2Scoped defaultScopes
|
||||||
|
|
||||||
oauth2AzureADv2Scoped
|
oauth2AzureADv2Scoped
|
||||||
:: YesodAuth m
|
:: YesodAuth m
|
||||||
=> [Text] -- ^ Scopes
|
=> [Text] -- ^ Scopes
|
||||||
-> Text
|
-> Text
|
||||||
-- ^ Tenant Id
|
-- ^ Tenant Id
|
||||||
--
|
--
|
||||||
-- If using a multi-tenant App, @common@ can be given here.
|
-- If using a multi-tenant App, @common@ can be given here.
|
||||||
--
|
--
|
||||||
-> Text -- ^ Client Id
|
-> Text -- ^ Client Id
|
||||||
-> Text -- ^ Client Secret
|
-> Text -- ^ Client Secret
|
||||||
-> AuthPlugin m
|
-> AuthPlugin m
|
||||||
oauth2AzureADv2Scoped scopes tenantId clientId clientSecret =
|
oauth2AzureADv2Scoped scopes tenantId clientId clientSecret =
|
||||||
authOAuth2 pluginName oauth2 $ \manager token -> do
|
authOAuth2 pluginName oauth2 $ \manager token -> do
|
||||||
(User userId, userResponse) <- authGetProfile
|
(User userId, userResponse) <- authGetProfile
|
||||||
pluginName
|
pluginName
|
||||||
manager
|
manager
|
||||||
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
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
oauth2 = OAuth2
|
oauth2 = OAuth2
|
||||||
{ oauth2ClientId = clientId
|
{ oauth2ClientId = clientId
|
||||||
, oauth2ClientSecret = Just clientSecret
|
, oauth2ClientSecret = Just clientSecret
|
||||||
, oauth2AuthorizeEndpoint =
|
, oauth2AuthorizeEndpoint =
|
||||||
tenantUrl "/authorize" `withQuery` [scopeParam " " scopes]
|
tenantUrl "/authorize" `withQuery` [scopeParam " " scopes]
|
||||||
, oauth2TokenEndpoint = tenantUrl "/token"
|
, oauth2TokenEndpoint = tenantUrl "/token"
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
tenantUrl path =
|
tenantUrl path =
|
||||||
fromString
|
fromString
|
||||||
$ "https://login.microsoftonline.com/"
|
$ "https://login.microsoftonline.com/"
|
||||||
<> unpack tenantId
|
<> unpack tenantId
|
||||||
<> "/oauth2/v2.0"
|
<> "/oauth2/v2.0"
|
||||||
<> path
|
<> path
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user