mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-04-28 05:38:01 +02:00
Restyled by brittany
This commit is contained in:
parent
80a410375a
commit
8427ab4128
154
example/Main.hs
154
example/Main.hs
@ -21,40 +21,42 @@
|
|||||||
--
|
--
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Aeson.Encode.Pretty
|
import Data.Aeson.Encode.Pretty
|
||||||
import Data.ByteString.Lazy (fromStrict, toStrict)
|
import Data.ByteString.Lazy ( fromStrict
|
||||||
import qualified Data.Map as M
|
, toStrict
|
||||||
import Data.Maybe (fromJust)
|
)
|
||||||
import Data.Text (Text)
|
import qualified Data.Map as M
|
||||||
import qualified Data.Text as T
|
import Data.Maybe ( fromJust )
|
||||||
import Data.Text.Encoding (decodeUtf8)
|
import Data.Text ( Text )
|
||||||
import LoadEnv
|
import qualified Data.Text as T
|
||||||
import Network.HTTP.Conduit
|
import Data.Text.Encoding ( decodeUtf8 )
|
||||||
import Network.Wai.Handler.Warp (runEnv)
|
import LoadEnv
|
||||||
import System.Environment (getEnv)
|
import Network.HTTP.Conduit
|
||||||
import Yesod
|
import Network.Wai.Handler.Warp ( runEnv )
|
||||||
import Yesod.Auth
|
import System.Environment ( getEnv )
|
||||||
import Yesod.Auth.OAuth2.AzureAD
|
import Yesod
|
||||||
import Yesod.Auth.OAuth2.BattleNet
|
import Yesod.Auth
|
||||||
import Yesod.Auth.OAuth2.Bitbucket
|
import Yesod.Auth.OAuth2.AzureAD
|
||||||
import Yesod.Auth.OAuth2.ClassLink
|
import Yesod.Auth.OAuth2.BattleNet
|
||||||
import Yesod.Auth.OAuth2.EveOnline
|
import Yesod.Auth.OAuth2.Bitbucket
|
||||||
import Yesod.Auth.OAuth2.GitHub
|
import Yesod.Auth.OAuth2.ClassLink
|
||||||
import Yesod.Auth.OAuth2.GitLab
|
import Yesod.Auth.OAuth2.EveOnline
|
||||||
import Yesod.Auth.OAuth2.Google
|
import Yesod.Auth.OAuth2.GitHub
|
||||||
import Yesod.Auth.OAuth2.Nylas
|
import Yesod.Auth.OAuth2.GitLab
|
||||||
import Yesod.Auth.OAuth2.Salesforce
|
import Yesod.Auth.OAuth2.Google
|
||||||
import Yesod.Auth.OAuth2.Slack
|
import Yesod.Auth.OAuth2.Nylas
|
||||||
import Yesod.Auth.OAuth2.Spotify
|
import Yesod.Auth.OAuth2.Salesforce
|
||||||
import Yesod.Auth.OAuth2.Twitch
|
import Yesod.Auth.OAuth2.Slack
|
||||||
import Yesod.Auth.OAuth2.Upcase
|
import Yesod.Auth.OAuth2.Spotify
|
||||||
import Yesod.Auth.OAuth2.WordPressDotCom
|
import Yesod.Auth.OAuth2.Twitch
|
||||||
|
import Yesod.Auth.OAuth2.Upcase
|
||||||
|
import Yesod.Auth.OAuth2.WordPressDotCom
|
||||||
|
|
||||||
data App = App
|
data App = App
|
||||||
{ appHttpManager :: Manager
|
{ appHttpManager :: Manager
|
||||||
, appAuthPlugins :: [AuthPlugin App]
|
, appAuthPlugins :: [AuthPlugin App]
|
||||||
}
|
}
|
||||||
|
|
||||||
mkYesod "App" [parseRoutes|
|
mkYesod "App" [parseRoutes|
|
||||||
/ RootR GET
|
/ RootR GET
|
||||||
@ -63,28 +65,28 @@ mkYesod "App" [parseRoutes|
|
|||||||
|
|
||||||
instance Yesod App where
|
instance Yesod App where
|
||||||
-- see https://github.com/thoughtbot/yesod-auth-oauth2/issues/87
|
-- see https://github.com/thoughtbot/yesod-auth-oauth2/issues/87
|
||||||
approot = ApprootStatic "http://localhost:3000"
|
approot = ApprootStatic "http://localhost:3000"
|
||||||
|
|
||||||
instance YesodAuth App where
|
instance YesodAuth App where
|
||||||
type AuthId App = Text
|
type AuthId App = Text
|
||||||
loginDest _ = RootR
|
loginDest _ = RootR
|
||||||
logoutDest _ = RootR
|
logoutDest _ = RootR
|
||||||
|
|
||||||
-- Disable any attempt to read persisted authenticated state
|
-- Disable any attempt to read persisted authenticated state
|
||||||
maybeAuthId = return Nothing
|
maybeAuthId = return Nothing
|
||||||
|
|
||||||
-- Copy the Creds response into the session for viewing after
|
-- Copy the Creds response into the session for viewing after
|
||||||
authenticate c = do
|
authenticate c = do
|
||||||
mapM_ (uncurry setSession)
|
mapM_ (uncurry setSession)
|
||||||
$ [("credsIdent", credsIdent c), ("credsPlugin", credsPlugin c)]
|
$ [("credsIdent", credsIdent c), ("credsPlugin", credsPlugin c)]
|
||||||
++ credsExtra c
|
++ credsExtra c
|
||||||
|
|
||||||
return $ Authenticated "1"
|
return $ Authenticated "1"
|
||||||
|
|
||||||
authPlugins = appAuthPlugins
|
authPlugins = appAuthPlugins
|
||||||
|
|
||||||
instance RenderMessage App FormMessage where
|
instance RenderMessage App FormMessage where
|
||||||
renderMessage _ _ = defaultFormMessage
|
renderMessage _ _ = defaultFormMessage
|
||||||
|
|
||||||
-- brittany-disable-next-binding
|
-- brittany-disable-next-binding
|
||||||
|
|
||||||
@ -127,38 +129,38 @@ getRootR = do
|
|||||||
|
|
||||||
mkFoundation :: IO App
|
mkFoundation :: IO App
|
||||||
mkFoundation = do
|
mkFoundation = do
|
||||||
loadEnv
|
loadEnv
|
||||||
|
|
||||||
appHttpManager <- newManager tlsManagerSettings
|
appHttpManager <- newManager tlsManagerSettings
|
||||||
appAuthPlugins <- sequence
|
appAuthPlugins <- sequence
|
||||||
-- When Providers are added, add them here and update .env.example.
|
-- When Providers are added, add them here and update .env.example.
|
||||||
-- Nothing else should need changing.
|
-- Nothing else should need changing.
|
||||||
--
|
--
|
||||||
-- FIXME: oauth2BattleNet is quite annoying!
|
-- FIXME: oauth2BattleNet is quite annoying!
|
||||||
--
|
--
|
||||||
[ loadPlugin oauth2AzureAD "AZURE_AD"
|
[ loadPlugin oauth2AzureAD "AZURE_AD"
|
||||||
, loadPlugin (oauth2BattleNet [whamlet|TODO|] "en") "BATTLE_NET"
|
, loadPlugin (oauth2BattleNet [whamlet|TODO|] "en") "BATTLE_NET"
|
||||||
, loadPlugin oauth2Bitbucket "BITBUCKET"
|
, loadPlugin oauth2Bitbucket "BITBUCKET"
|
||||||
, loadPlugin oauth2ClassLink "CLASSLINK"
|
, loadPlugin oauth2ClassLink "CLASSLINK"
|
||||||
, loadPlugin (oauth2Eve Plain) "EVE_ONLINE"
|
, loadPlugin (oauth2Eve Plain) "EVE_ONLINE"
|
||||||
, loadPlugin oauth2GitHub "GITHUB"
|
, loadPlugin oauth2GitHub "GITHUB"
|
||||||
, loadPlugin oauth2GitLab "GITLAB"
|
, loadPlugin oauth2GitLab "GITLAB"
|
||||||
, loadPlugin oauth2Google "GOOGLE"
|
, loadPlugin oauth2Google "GOOGLE"
|
||||||
, loadPlugin oauth2Nylas "NYLAS"
|
, loadPlugin oauth2Nylas "NYLAS"
|
||||||
, loadPlugin oauth2Salesforce "SALES_FORCE"
|
, loadPlugin oauth2Salesforce "SALES_FORCE"
|
||||||
, loadPlugin oauth2Slack "SLACK"
|
, loadPlugin oauth2Slack "SLACK"
|
||||||
, loadPlugin (oauth2Spotify []) "SPOTIFY"
|
, loadPlugin (oauth2Spotify []) "SPOTIFY"
|
||||||
, loadPlugin oauth2Twitch "TWITCH"
|
, loadPlugin oauth2Twitch "TWITCH"
|
||||||
, loadPlugin oauth2WordPressDotCom "WORDPRESS_DOT_COM"
|
, loadPlugin oauth2WordPressDotCom "WORDPRESS_DOT_COM"
|
||||||
, loadPlugin oauth2Upcase "UPCASE"
|
, loadPlugin oauth2Upcase "UPCASE"
|
||||||
]
|
]
|
||||||
|
|
||||||
return App { .. }
|
return App { .. }
|
||||||
where
|
where
|
||||||
loadPlugin f prefix = do
|
loadPlugin f prefix = do
|
||||||
clientId <- getEnv $ prefix <> "_CLIENT_ID"
|
clientId <- getEnv $ prefix <> "_CLIENT_ID"
|
||||||
clientSecret <- getEnv $ prefix <> "_CLIENT_SECRET"
|
clientSecret <- getEnv $ prefix <> "_CLIENT_SECRET"
|
||||||
pure $ f (T.pack clientId) (T.pack clientSecret)
|
pure $ f (T.pack clientId) (T.pack clientSecret)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = runEnv 3000 =<< toWaiApp =<< mkFoundation
|
main = runEnv 3000 =<< toWaiApp =<< mkFoundation
|
||||||
|
|||||||
@ -11,9 +11,9 @@ module Yesod.Auth.OAuth2.Twitch
|
|||||||
, oauth2TwitchScoped
|
, oauth2TwitchScoped
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Yesod.Auth.OAuth2.Prelude
|
import Yesod.Auth.OAuth2.Prelude
|
||||||
|
|
||||||
import qualified Data.Text.Encoding as T
|
import qualified Data.Text.Encoding as T
|
||||||
|
|
||||||
newtype User = User Text
|
newtype User = User Text
|
||||||
|
|
||||||
@ -50,7 +50,9 @@ oauth2TwitchScoped scopes clientId clientSecret =
|
|||||||
`withQuery` [scopeParam " " scopes]
|
`withQuery` [scopeParam " " scopes]
|
||||||
, oauth2TokenEndpoint = "https://id.twitch.tv/oauth2/token"
|
, oauth2TokenEndpoint = "https://id.twitch.tv/oauth2/token"
|
||||||
`withQuery` [ ("client_id", T.encodeUtf8 clientId)
|
`withQuery` [ ("client_id", T.encodeUtf8 clientId)
|
||||||
, ("client_secret", T.encodeUtf8 clientSecret)
|
, ( "client_secret"
|
||||||
|
, T.encodeUtf8 clientSecret
|
||||||
|
)
|
||||||
]
|
]
|
||||||
, oauth2RedirectUri = Nothing
|
, oauth2RedirectUri = Nothing
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user