Skip to content

Commit 2c2ce03

Browse files
committed
add option to customize widget for azure AD v2
1 parent d0606fb commit 2c2ce03

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/Yesod/Auth/OAuth2/AzureADv2.hs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE QuasiQuotes #-}
23

34
-- |
45
--
@@ -9,9 +10,12 @@
910
module Yesod.Auth.OAuth2.AzureADv2
1011
( oauth2AzureADv2
1112
, oauth2AzureADv2Scoped
13+
, oauth2AzureADv2Widget
14+
, oauth2AzureADv2ScopedWidget
1215
) where
1316

1417
import Yesod.Auth.OAuth2.Prelude
18+
import Yesod.Core (WidgetFor, whamlet)
1519
import Prelude
1620

1721
import Data.String
@@ -41,9 +45,20 @@ oauth2AzureADv2
4145
-> AuthPlugin m
4246
oauth2AzureADv2 = oauth2AzureADv2Scoped defaultScopes
4347

44-
oauth2AzureADv2Scoped
48+
oauth2AzureADv2Widget
49+
:: YesodAuth m => WidgetFor m () -> Text -> Text -> Text -> AuthPlugin m
50+
oauth2AzureADv2Widget widget =
51+
oauth2AzureADv2ScopedWidget widget defaultScopes
52+
53+
oauth2AzureADv2Scoped :: YesodAuth m => [Text] -> Text -> Text -> Text -> AuthPlugin m
54+
oauth2AzureADv2Scoped =
55+
oauth2AzureADv2ScopedWidget [whamlet|Login via #{pluginName}|]
56+
57+
oauth2AzureADv2ScopedWidget
4558
:: YesodAuth m
46-
=> [Text]
59+
=> WidgetFor m ()
60+
-- ^ Widget
61+
-> [Text]
4762
-- ^ Scopes
4863
-> Text
4964
-- ^ Tenant Id
@@ -54,8 +69,8 @@ oauth2AzureADv2Scoped
5469
-> Text
5570
-- ^ Client Secret
5671
-> AuthPlugin m
57-
oauth2AzureADv2Scoped scopes tenantId clientId clientSecret =
58-
authOAuth2 pluginName oauth2 $ \manager token -> do
72+
oauth2AzureADv2ScopedWidget widget scopes tenantId clientId clientSecret =
73+
authOAuth2Widget widget pluginName oauth2 $ \manager token -> do
5974
(User userId, userResponse) <-
6075
authGetProfile
6176
pluginName

0 commit comments

Comments
 (0)