mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-04-27 21:27:54 +02:00
add custom scope and/or widget options to GitHub plugin
This commit is contained in:
parent
94ba2ebeab
commit
730909a7cd
@ -1,4 +1,5 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
|
||||||
-- |
|
-- |
|
||||||
--
|
--
|
||||||
@ -8,11 +9,13 @@
|
|||||||
-- * Uses github user id as credentials identifier
|
-- * Uses github user id as credentials identifier
|
||||||
module Yesod.Auth.OAuth2.GitHub
|
module Yesod.Auth.OAuth2.GitHub
|
||||||
( oauth2GitHub
|
( oauth2GitHub
|
||||||
|
, oauth2GitHubWidget
|
||||||
, oauth2GitHubScoped
|
, oauth2GitHubScoped
|
||||||
|
, oauth2GitHubScopedWidget
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
import Yesod.Core (WidgetFor, whamlet)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
|
||||||
newtype User = User Int
|
newtype User = User Int
|
||||||
@ -29,9 +32,17 @@ defaultScopes = ["user:email"]
|
|||||||
oauth2GitHub :: YesodAuth m => Text -> Text -> AuthPlugin m
|
oauth2GitHub :: YesodAuth m => Text -> Text -> AuthPlugin m
|
||||||
oauth2GitHub = oauth2GitHubScoped defaultScopes
|
oauth2GitHub = oauth2GitHubScoped defaultScopes
|
||||||
|
|
||||||
|
oauth2GitHubWidget :: YesodAuth m => WidgetFor m () -> Text -> Text -> AuthPlugin m
|
||||||
|
oauth2GitHubWidget widget = oauth2GitHubScopedWidget widget defaultScopes
|
||||||
|
|
||||||
oauth2GitHubScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
|
oauth2GitHubScoped :: YesodAuth m => [Text] -> Text -> Text -> AuthPlugin m
|
||||||
oauth2GitHubScoped scopes clientId clientSecret =
|
oauth2GitHubScoped =
|
||||||
authOAuth2 pluginName oauth2 $ \manager token -> do
|
oauth2GitHubScopedWidget [whamlet|Login via #{pluginName}|]
|
||||||
|
|
||||||
|
oauth2GitHubScopedWidget
|
||||||
|
:: YesodAuth m => WidgetFor m () ->[Text] -> Text -> Text -> AuthPlugin m
|
||||||
|
oauth2GitHubScopedWidget widget scopes clientId clientSecret =
|
||||||
|
authOAuth2Widget widget pluginName oauth2 $ \manager token -> do
|
||||||
(User userId, userResponse) <-
|
(User userId, userResponse) <-
|
||||||
authGetProfile
|
authGetProfile
|
||||||
pluginName
|
pluginName
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user