yesod-auth-oauth2 0.7.0.2 → 0.7.0.3
raw patch · 6 files changed
+86/−56 lines, 6 filesdep ~aeson-prettydep ~errorsdep ~hspecPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: aeson-pretty, errors, hspec, load-env, memory, microlens, mtl, safe-exceptions, transformers, unliftio, uri-bytestring, warp, yesod
API changes (from Hackage documentation)
+ Network.OAuth.OAuth2.Compat: type Errors = OAuth2Error Errors
- Network.OAuth.OAuth2.Compat: type OAuth2Result err a = Either (OAuth2Error err) a
+ Network.OAuth.OAuth2.Compat: type OAuth2Result err a = Either err a
- Yesod.Auth.OAuth2.DispatchError: OAuth2ResultError :: OAuth2Error Errors -> DispatchError
+ Yesod.Auth.OAuth2.DispatchError: OAuth2ResultError :: Errors -> DispatchError
Files
- CHANGELOG.md +6/−1
- README.md +6/−0
- src/Network/OAuth/OAuth2/Compat.hs +26/−5
- src/Yesod/Auth/OAuth2/Dispatch.hs +0/−1
- src/Yesod/Auth/OAuth2/DispatchError.hs +31/−32
- yesod-auth-oauth2.cabal +17/−17
CHANGELOG.md view
@@ -1,4 +1,9 @@-## [_Unreleased_](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.7.0.2...main)+## [_Unreleased_](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.7.0.3...main)++## [v0.7.0.3](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.7.0.2...v0.7.0.3)++- Support `hoauth-2.7`. This change is only breaking in the unlikely case of users+ using something other than `fetchAccessToken` or `fetchAccessToken2` ## [v0.7.0.2](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.7.0.1...v0.7.0.2)
README.md view
@@ -1,5 +1,11 @@ # Yesod.Auth.OAuth2 ++[](https://hackage.haskell.org/package/yesod-auth-oauth2)+[](http://stackage.org/nightly/package/yesod-auth-oauth2)+[](http://stackage.org/lts/package/yesod-auth-oauth2)+[](https://github.com/pbrisbin/freckle/yesod-auth-oauth2/workflows/ci.yml)+ OAuth2 `AuthPlugin`s for Yesod. ## Usage
src/Network/OAuth/OAuth2/Compat.hs view
@@ -3,6 +3,7 @@ module Network.OAuth.OAuth2.Compat ( OAuth2(..) , OAuth2Result+ , Errors , authorizationUrl , fetchAccessToken , fetchAccessToken2@@ -15,15 +16,25 @@ import Data.ByteString.Lazy (ByteString) import Data.Text (Text) import Network.HTTP.Conduit (Manager)+import qualified Network.OAuth.OAuth2 as OAuth2+#if MIN_VERSION_hoauth2(2,7,0) import Network.OAuth.OAuth2 ( AccessToken(..) , ExchangeToken(..)+ , OAuth2Token(..)+ , RefreshToken(..)+ )+import Network.OAuth.OAuth2.TokenRequest (TokenRequestError)+#else+import Network.OAuth.OAuth2+ ( AccessToken(..)+ , ExchangeToken(..) , OAuth2Error , OAuth2Token(..) , RefreshToken(..) )-import qualified Network.OAuth.OAuth2 as OAuth2-import Network.OAuth.OAuth2.TokenRequest (Errors)+import qualified Network.OAuth.OAuth2.TokenRequest as LegacyTokenRequest+#endif import URI.ByteString #if MIN_VERSION_hoauth2(2,2,0)@@ -39,8 +50,14 @@ , oauth2RedirectUri :: Maybe (URIRef Absolute) } -type OAuth2Result err a = Either (OAuth2Error err) a+#if MIN_VERSION_hoauth2(2,7,0)+type Errors = TokenRequestError+#else+type Errors = OAuth2Error LegacyTokenRequest.Errors+#endif +type OAuth2Result err a = Either err a+ authorizationUrl :: OAuth2 -> URI authorizationUrl = OAuth2.authorizationUrl . getOAuth2 @@ -134,7 +151,9 @@ -> IO (OAuth2Result Errors OAuth2Token) fetchAccessTokenBasic m o e = runOAuth2 $ f m (getOAuth2 o) e where-#if MIN_VERSION_hoauth2(2,3,0)+#if MIN_VERSION_hoauth2(2,6,0)+ f = OAuth2.fetchAccessTokenWithAuthMethod OAuth2.ClientSecretBasic+#elif MIN_VERSION_hoauth2(2,3,0) f = OAuth2.fetchAccessTokenInternal OAuth2.ClientSecretBasic #else f = OAuth2.fetchAccessToken@@ -147,7 +166,9 @@ -> IO (OAuth2Result Errors OAuth2Token) fetchAccessTokenPost m o e = runOAuth2 $ f m (getOAuth2 o) e where-#if MIN_VERSION_hoauth2(2,3,0)+#if MIN_VERSION_hoauth2(2, 6, 0)+ f = OAuth2.fetchAccessTokenWithAuthMethod OAuth2.ClientSecretPost+#elif MIN_VERSION_hoauth2(2,3,0) f = OAuth2.fetchAccessTokenInternal OAuth2.ClientSecretPost #else f = OAuth2.fetchAccessToken2
src/Yesod/Auth/OAuth2/Dispatch.hs view
@@ -18,7 +18,6 @@ import Data.Text.Encoding (encodeUtf8) import Network.HTTP.Conduit (Manager) import Network.OAuth.OAuth2.Compat-import Network.OAuth.OAuth2.TokenRequest (Errors) import URI.ByteString.Extension import UnliftIO.Exception import Yesod.Auth hiding (ServerError)
src/Yesod/Auth/OAuth2/DispatchError.hs view
@@ -9,15 +9,14 @@ {-# LANGUAGE TypeFamilies #-} module Yesod.Auth.OAuth2.DispatchError- ( DispatchError(..)- , handleDispatchError- , onDispatchError- ) where+ ( DispatchError(..)+ , handleDispatchError+ , onDispatchError+ ) where import Control.Monad.Except import Data.Text (Text, pack)-import Network.OAuth.OAuth2-import Network.OAuth.OAuth2.TokenRequest (Errors)+import Network.OAuth.OAuth2.Compat (Errors) import UnliftIO.Except () import UnliftIO.Exception import Yesod.Auth hiding (ServerError)@@ -31,7 +30,7 @@ | InvalidStateToken (Maybe Text) Text | InvalidCallbackUri Text | OAuth2HandshakeError ErrorResponse- | OAuth2ResultError (OAuth2Error Errors)+ | OAuth2ResultError Errors | FetchCredsIOException IOException | FetchCredsYesodOAuth2Exception YesodOAuth2Exception | OtherDispatchError Text@@ -45,37 +44,37 @@ -- dispatchErrorMessage :: DispatchError -> Text dispatchErrorMessage = \case- MissingParameter name ->- "Parameter '" <> name <> "' is required, but not present in the URL"- InvalidStateToken{} -> "State token is invalid, please try again"- InvalidCallbackUri{}- -> "Callback URI was not valid, this server may be misconfigured (no approot)"- OAuth2HandshakeError er -> "OAuth2 handshake failure: " <> erUserMessage er- OAuth2ResultError{} -> "Login failed, please try again"- FetchCredsIOException{} -> "Login failed, please try again"- FetchCredsYesodOAuth2Exception{} -> "Login failed, please try again"- OtherDispatchError{} -> "Login failed, please try again"+ MissingParameter name ->+ "Parameter '" <> name <> "' is required, but not present in the URL"+ InvalidStateToken{} -> "State token is invalid, please try again"+ InvalidCallbackUri{} ->+ "Callback URI was not valid, this server may be misconfigured (no approot)"+ OAuth2HandshakeError er -> "OAuth2 handshake failure: " <> erUserMessage er+ OAuth2ResultError{} -> "Login failed, please try again"+ FetchCredsIOException{} -> "Login failed, please try again"+ FetchCredsYesodOAuth2Exception{} -> "Login failed, please try again"+ OtherDispatchError{} -> "Login failed, please try again" handleDispatchError- :: MonadAuthHandler site m- => ExceptT DispatchError m TypedContent- -> m TypedContent+ :: MonadAuthHandler site m+ => ExceptT DispatchError m TypedContent+ -> m TypedContent handleDispatchError f = do- result <- runExceptT f- either onDispatchError pure result+ result <- runExceptT f+ either onDispatchError pure result onDispatchError :: MonadAuthHandler site m => DispatchError -> m TypedContent onDispatchError err = do- errorId <- liftIO $ randomText 16- let suffix = " [errorId=" <> errorId <> "]"- $(logError) $ pack (displayException err) <> suffix+ errorId <- liftIO $ randomText 16+ let suffix = " [errorId=" <> errorId <> "]"+ $(logError) $ pack (displayException err) <> suffix - let message = dispatchErrorMessage err <> suffix- messageValue =- object ["error" .= object ["id" .= errorId, "message" .= message]]+ let message = dispatchErrorMessage err <> suffix+ messageValue =+ object ["error" .= object ["id" .= errorId, "message" .= message]] - loginR <- ($ LoginR) <$> getRouteToParent+ loginR <- ($ LoginR) <$> getRouteToParent - selectRep $ do- provideRep @_ @Html $ onErrorHtml loginR message- provideRep @_ @Value $ pure messageValue+ selectRep $ do+ provideRep @_ @Html $ onErrorHtml loginR message+ provideRep @_ @Value $ pure messageValue
yesod-auth-oauth2.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: yesod-auth-oauth2-version: 0.7.0.2+version: 0.7.0.3 license: MIT license-file: LICENSE maintainer: engineering@freckle.com@@ -67,19 +67,19 @@ base >=4.9.0.0 && <5, bytestring >=0.9.1.4, cryptonite >=0.25,- errors >=2.3.0,+ errors, hoauth2 >=1.11.0, http-client >=0.4.0, http-conduit >=2.0, http-types >=0.8,- memory >=0.14.18,- microlens >=0.4.10,- mtl >=2.2.2,- safe-exceptions >=0.1.7.0,+ memory,+ microlens,+ mtl,+ safe-exceptions, text >=0.7,- transformers >=0.5.5.0,- unliftio >=0.2.10,- uri-bytestring >=0.3.2.1,+ transformers,+ unliftio,+ uri-bytestring, yesod-auth >=1.6.0, yesod-core >=1.6.0 @@ -91,17 +91,17 @@ ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N build-depends: aeson >=0.6,- aeson-pretty >=0.8.7,+ aeson-pretty, base >=4.9.0.0 && <5, bytestring >=0.9.1.4, containers >=0.6.0.1, http-conduit >=2.0,- load-env >=0.2.0.2,+ load-env, text >=0.7,- warp >=3.2.25,- yesod >=1.6.0,+ warp,+ yesod, yesod-auth >=1.6.0,- yesod-auth-oauth2 -any+ yesod-auth-oauth2 if !flag(example) buildable: False@@ -118,6 +118,6 @@ ghc-options: -Wall build-depends: base >=4.9.0.0 && <5,- hspec >=2.6.1,- uri-bytestring >=0.3.2.1,- yesod-auth-oauth2 -any+ hspec,+ uri-bytestring,+ yesod-auth-oauth2