hoauth2-providers-tutorial 0.1 → 0.2
raw patch · 3 files changed
+55/−57 lines, 3 filesdep ~hoauth2dep ~hoauth2-providersPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hoauth2, hoauth2-providers
API changes (from Hackage documentation)
- HOAuth2ProvidersTutorial: oauth2ErrorToText :: OAuth2Error Errors -> Text
+ HOAuth2ProvidersTutorial: oauth2ErrorToText :: TokenRequestError -> Text
Files
- app/Main.hs +1/−2
- hoauth2-providers-tutorial.cabal +3/−3
- src/HOAuth2ProvidersTutorial.hs +51/−52
app/Main.hs view
@@ -1,6 +1,5 @@--- |- module Main where+ import HOAuth2ProvidersTutorial (app) main :: IO ()
hoauth2-providers-tutorial.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: hoauth2-providers-tutorial-version: 0.1+version: 0.2 synopsis: tutorial for hoauth2-providers module description: A tutorial that demostrates how to use hoauth2-providers package@@ -19,8 +19,8 @@ , base >=4.14 && <5 , bytestring >=0.9 && <0.12 , containers- , hoauth2 ^>=2.6- , hoauth2-providers ^>=0.1+ , hoauth2 >=2.7+ , hoauth2-providers >=0.2 , http-conduit >=2.1 && <2.4 , http-types >=0.11 && <0.13 , scotty >=0.10.0 && <0.13
src/HOAuth2ProvidersTutorial.hs view
@@ -18,25 +18,24 @@ import Data.Text.Lazy qualified as TL import Network.HTTP.Conduit (newManager, tlsManagerSettings) import Network.HTTP.Types (status302)-import Network.OAuth.OAuth2.Internal- ( ExchangeToken (ExchangeToken),- OAuth2Error,- OAuth2Token (accessToken),- )-import Network.OAuth.OAuth2.TokenRequest qualified as TR+import Network.OAuth.OAuth2 (+ ExchangeToken (ExchangeToken),+ OAuth2Token (accessToken),+ TokenRequestError,+ ) import Network.OAuth2.Experiment-import Network.OAuth2.Provider.Auth0- ( Auth0,- Auth0User (Auth0User, email, name, sub),- defaultAuth0App,- defaultAuth0Idp,- )-import Network.OAuth2.Provider.Google- ( Google,- GoogleUser (GoogleUser, email, id, name),- defaultGoogleApp,- defaultGoogleIdp,- )+import Network.OAuth2.Provider.Auth0 (+ Auth0,+ Auth0User (Auth0User, email, name, sub),+ defaultAuth0App,+ defaultAuth0Idp,+ )+import Network.OAuth2.Provider.Google (+ Google,+ GoogleUser (GoogleUser, email, id, name),+ defaultGoogleApp,+ defaultGoogleIdp,+ ) import URI.ByteString (URI, serializeURIRef') import URI.ByteString.QQ (uri) import Web.Scotty (ActionM, scotty)@@ -51,21 +50,21 @@ testAuth0App :: IdpApplication 'AuthorizationCode Auth0 testAuth0App =- ( defaultAuth0App testAuth0Idp )- { idpAppClientId = "",- idpAppClientSecret = "",- idpAppAuthorizeState = AuthorizeState ("auth0." <> randomStateValue),- idpAppScope = Set.fromList ["openid", "email", "profile"],- idpAppRedirectUri = [uri|http://localhost:9988/oauth2/callback|],- idpAppName = "foo-auth0-app"+ (defaultAuth0App testAuth0Idp)+ { idpAppClientId = ""+ , idpAppClientSecret = ""+ , idpAppAuthorizeState = AuthorizeState ("auth0." <> randomStateValue)+ , idpAppScope = Set.fromList ["openid", "email", "profile"]+ , idpAppRedirectUri = [uri|http://localhost:9988/oauth2/callback|]+ , idpAppName = "foo-auth0-app" } testAuth0Idp :: Idp Auth0 testAuth0Idp = defaultAuth0Idp- { idpUserInfoEndpoint = [uri|https://freizl.auth0.com/userinfo|],- idpAuthorizeEndpoint = [uri|https://freizl.auth0.com/authorize|],- idpTokenEndpoint = [uri|https://freizl.auth0.com/oauth/token|]+ { idpUserInfoEndpoint = [uri|https://freizl.auth0.com/userinfo|]+ , idpAuthorizeEndpoint = [uri|https://freizl.auth0.com/authorize|]+ , idpTokenEndpoint = [uri|https://freizl.auth0.com/oauth/token|] } testGoogleIdp :: Idp Google@@ -74,12 +73,12 @@ testGoogleApp :: IdpApplication 'AuthorizationCode Google testGoogleApp = defaultGoogleApp- { idpAppClientId = "",- idpAppClientSecret = "",- idpAppAuthorizeState = AuthorizeState ("google." <> randomStateValue),- idpAppRedirectUri = [uri|http://localhost:9988/oauth2/callback|],- idpAppName = "foo-google-app",- idp = testGoogleIdp+ { idpAppClientId = ""+ , idpAppClientSecret = ""+ , idpAppAuthorizeState = AuthorizeState ("google." <> randomStateValue)+ , idpAppRedirectUri = [uri|http://localhost:9988/oauth2/callback|]+ , idpAppName = "foo-google-app"+ , idp = testGoogleIdp } -- | You'll need to find out an better way to create @state@@@ -93,8 +92,8 @@ ------------------------------ data DemoUser = DemoUser- { name :: TL.Text,- email :: Maybe TL.Text+ { name :: TL.Text+ , email :: Maybe TL.Text } deriving (Eq, Show) @@ -117,23 +116,23 @@ let info = case muser of Just DemoUser {..} ->- [ "<h2>Hello, ",- name,- "</h2>",- "<p>",- TL.pack (show email),- "</p>",- "<a href='/logout'>Logout</a>"+ [ "<h2>Hello, "+ , name+ , "</h2>"+ , "<p>"+ , TL.pack (show email)+ , "</p>"+ , "<a href='/logout'>Logout</a>" ] Nothing ->- [ "<ul>",- "<li>",- "<a href='/login/auth0'>Login with Auth0</a>",- "</li>",- "<li>",- "<a href='/login/google'>Login with Google</a>",- "</li>",- "</ul>"+ [ "<ul>"+ , "<li>"+ , "<a href='/login/auth0'>Login with Auth0</a>"+ , "</li>"+ , "<li>"+ , "<a href='/login/google'>Login with Google</a>"+ , "</li>"+ , "</ul>" ] Scotty.html . mconcat $ "<h1>hoauth2 providers Tutorial</h1>" : info@@ -226,5 +225,5 @@ result <- liftIO $ runExceptT e either Scotty.raise pure result -oauth2ErrorToText :: OAuth2Error TR.Errors -> TL.Text+oauth2ErrorToText :: TokenRequestError -> TL.Text oauth2ErrorToText e = TL.pack $ "Unable fetch access token. error detail: " ++ show e