mirror of
https://github.com/freckle/yesod-auth-oauth2.git
synced 2026-09-05 17:33:49 +02:00
Fix hoauth2 compat for 2.7.0 (#165)
Use CPP to get 2.7.0 to compile Resolves #164
This commit is contained in:
parent
36805f0580
commit
3c15ecd871
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -20,6 +20,7 @@ jobs:
|
|||||||
- stack-hoauth2-2.0.yaml
|
- stack-hoauth2-2.0.yaml
|
||||||
- stack-hoauth2-2.2.yaml
|
- stack-hoauth2-2.2.yaml
|
||||||
- stack-hoauth2-2.3.yaml
|
- stack-hoauth2-2.3.yaml
|
||||||
|
- stack-hoauth2-2.6.yaml
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@ -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)
|
## [v0.7.0.2](https://github.com/thoughtbot/yesod-auth-oauth2/compare/v0.7.0.1...v0.7.0.2)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: yesod-auth-oauth2
|
name: yesod-auth-oauth2
|
||||||
version: 0.7.0.2
|
version: 0.7.0.3
|
||||||
synopsis: OAuth 2.0 authentication plugins
|
synopsis: OAuth 2.0 authentication plugins
|
||||||
description: Library to authenticate with OAuth 2.0 for Yesod web applications.
|
description: Library to authenticate with OAuth 2.0 for Yesod web applications.
|
||||||
category: Web
|
category: Web
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
module Network.OAuth.OAuth2.Compat
|
module Network.OAuth.OAuth2.Compat
|
||||||
( OAuth2(..)
|
( OAuth2(..)
|
||||||
, OAuth2Result
|
, OAuth2Result
|
||||||
|
, Errors
|
||||||
, authorizationUrl
|
, authorizationUrl
|
||||||
, fetchAccessToken
|
, fetchAccessToken
|
||||||
, fetchAccessToken2
|
, fetchAccessToken2
|
||||||
@ -15,6 +16,16 @@ module Network.OAuth.OAuth2.Compat
|
|||||||
import Data.ByteString.Lazy (ByteString)
|
import Data.ByteString.Lazy (ByteString)
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Network.HTTP.Conduit (Manager)
|
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
|
import Network.OAuth.OAuth2
|
||||||
( AccessToken(..)
|
( AccessToken(..)
|
||||||
, ExchangeToken(..)
|
, ExchangeToken(..)
|
||||||
@ -22,8 +33,8 @@ import Network.OAuth.OAuth2
|
|||||||
, OAuth2Token(..)
|
, OAuth2Token(..)
|
||||||
, RefreshToken(..)
|
, RefreshToken(..)
|
||||||
)
|
)
|
||||||
import qualified Network.OAuth.OAuth2 as OAuth2
|
import qualified Network.OAuth.OAuth2.TokenRequest as LegacyTokenRequest
|
||||||
import Network.OAuth.OAuth2.TokenRequest (Errors)
|
#endif
|
||||||
import URI.ByteString
|
import URI.ByteString
|
||||||
|
|
||||||
#if MIN_VERSION_hoauth2(2,2,0)
|
#if MIN_VERSION_hoauth2(2,2,0)
|
||||||
@ -39,7 +50,13 @@ data OAuth2 = OAuth2
|
|||||||
, oauth2RedirectUri :: Maybe (URIRef Absolute)
|
, 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 -> URI
|
||||||
authorizationUrl = OAuth2.authorizationUrl . getOAuth2
|
authorizationUrl = OAuth2.authorizationUrl . getOAuth2
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import qualified Data.Text as T
|
|||||||
import Data.Text.Encoding (encodeUtf8)
|
import Data.Text.Encoding (encodeUtf8)
|
||||||
import Network.HTTP.Conduit (Manager)
|
import Network.HTTP.Conduit (Manager)
|
||||||
import Network.OAuth.OAuth2.Compat
|
import Network.OAuth.OAuth2.Compat
|
||||||
import Network.OAuth.OAuth2.TokenRequest (Errors)
|
|
||||||
import URI.ByteString.Extension
|
import URI.ByteString.Extension
|
||||||
import UnliftIO.Exception
|
import UnliftIO.Exception
|
||||||
import Yesod.Auth hiding (ServerError)
|
import Yesod.Auth hiding (ServerError)
|
||||||
|
|||||||
@ -9,15 +9,14 @@
|
|||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
|
|
||||||
module Yesod.Auth.OAuth2.DispatchError
|
module Yesod.Auth.OAuth2.DispatchError
|
||||||
( DispatchError(..)
|
( DispatchError(..)
|
||||||
, handleDispatchError
|
, handleDispatchError
|
||||||
, onDispatchError
|
, onDispatchError
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Except
|
import Control.Monad.Except
|
||||||
import Data.Text (Text, pack)
|
import Data.Text (Text, pack)
|
||||||
import Network.OAuth.OAuth2
|
import Network.OAuth.OAuth2.Compat (Errors)
|
||||||
import Network.OAuth.OAuth2.TokenRequest (Errors)
|
|
||||||
import UnliftIO.Except ()
|
import UnliftIO.Except ()
|
||||||
import UnliftIO.Exception
|
import UnliftIO.Exception
|
||||||
import Yesod.Auth hiding (ServerError)
|
import Yesod.Auth hiding (ServerError)
|
||||||
@ -31,7 +30,7 @@ data DispatchError
|
|||||||
| InvalidStateToken (Maybe Text) Text
|
| InvalidStateToken (Maybe Text) Text
|
||||||
| InvalidCallbackUri Text
|
| InvalidCallbackUri Text
|
||||||
| OAuth2HandshakeError ErrorResponse
|
| OAuth2HandshakeError ErrorResponse
|
||||||
| OAuth2ResultError (OAuth2Error Errors)
|
| OAuth2ResultError Errors
|
||||||
| FetchCredsIOException IOException
|
| FetchCredsIOException IOException
|
||||||
| FetchCredsYesodOAuth2Exception YesodOAuth2Exception
|
| FetchCredsYesodOAuth2Exception YesodOAuth2Exception
|
||||||
| OtherDispatchError Text
|
| OtherDispatchError Text
|
||||||
@ -45,37 +44,37 @@ data DispatchError
|
|||||||
--
|
--
|
||||||
dispatchErrorMessage :: DispatchError -> Text
|
dispatchErrorMessage :: DispatchError -> Text
|
||||||
dispatchErrorMessage = \case
|
dispatchErrorMessage = \case
|
||||||
MissingParameter name ->
|
MissingParameter name ->
|
||||||
"Parameter '" <> name <> "' is required, but not present in the URL"
|
"Parameter '" <> name <> "' is required, but not present in the URL"
|
||||||
InvalidStateToken{} -> "State token is invalid, please try again"
|
InvalidStateToken{} -> "State token is invalid, please try again"
|
||||||
InvalidCallbackUri{}
|
InvalidCallbackUri{} ->
|
||||||
-> "Callback URI was not valid, this server may be misconfigured (no approot)"
|
"Callback URI was not valid, this server may be misconfigured (no approot)"
|
||||||
OAuth2HandshakeError er -> "OAuth2 handshake failure: " <> erUserMessage er
|
OAuth2HandshakeError er -> "OAuth2 handshake failure: " <> erUserMessage er
|
||||||
OAuth2ResultError{} -> "Login failed, please try again"
|
OAuth2ResultError{} -> "Login failed, please try again"
|
||||||
FetchCredsIOException{} -> "Login failed, please try again"
|
FetchCredsIOException{} -> "Login failed, please try again"
|
||||||
FetchCredsYesodOAuth2Exception{} -> "Login failed, please try again"
|
FetchCredsYesodOAuth2Exception{} -> "Login failed, please try again"
|
||||||
OtherDispatchError{} -> "Login failed, please try again"
|
OtherDispatchError{} -> "Login failed, please try again"
|
||||||
|
|
||||||
handleDispatchError
|
handleDispatchError
|
||||||
:: MonadAuthHandler site m
|
:: MonadAuthHandler site m
|
||||||
=> ExceptT DispatchError m TypedContent
|
=> ExceptT DispatchError m TypedContent
|
||||||
-> m TypedContent
|
-> m TypedContent
|
||||||
handleDispatchError f = do
|
handleDispatchError f = do
|
||||||
result <- runExceptT f
|
result <- runExceptT f
|
||||||
either onDispatchError pure result
|
either onDispatchError pure result
|
||||||
|
|
||||||
onDispatchError :: MonadAuthHandler site m => DispatchError -> m TypedContent
|
onDispatchError :: MonadAuthHandler site m => DispatchError -> m TypedContent
|
||||||
onDispatchError err = do
|
onDispatchError err = do
|
||||||
errorId <- liftIO $ randomText 16
|
errorId <- liftIO $ randomText 16
|
||||||
let suffix = " [errorId=" <> errorId <> "]"
|
let suffix = " [errorId=" <> errorId <> "]"
|
||||||
$(logError) $ pack (displayException err) <> suffix
|
$(logError) $ pack (displayException err) <> suffix
|
||||||
|
|
||||||
let message = dispatchErrorMessage err <> suffix
|
let message = dispatchErrorMessage err <> suffix
|
||||||
messageValue =
|
messageValue =
|
||||||
object ["error" .= object ["id" .= errorId, "message" .= message]]
|
object ["error" .= object ["id" .= errorId, "message" .= message]]
|
||||||
|
|
||||||
loginR <- ($ LoginR) <$> getRouteToParent
|
loginR <- ($ LoginR) <$> getRouteToParent
|
||||||
|
|
||||||
selectRep $ do
|
selectRep $ do
|
||||||
provideRep @_ @Html $ onErrorHtml loginR message
|
provideRep @_ @Html $ onErrorHtml loginR message
|
||||||
provideRep @_ @Value $ pure messageValue
|
provideRep @_ @Value $ pure messageValue
|
||||||
|
|||||||
11
stack-hoauth2-2.6.yaml
Normal file
11
stack-hoauth2-2.6.yaml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
resolver: nightly-2022-12-09
|
||||||
|
|
||||||
|
extra-deps:
|
||||||
|
- hoauth2-2.6.0
|
||||||
|
|
||||||
|
# hoauth2 needs upper-bounds relaxed for
|
||||||
|
#
|
||||||
|
# - memory-0.18.0
|
||||||
|
# - text-2.0.1
|
||||||
|
#
|
||||||
|
allow-newer: true
|
||||||
19
stack-hoauth2-2.6.yaml.lock
Normal file
19
stack-hoauth2-2.6.yaml.lock
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# This file was autogenerated by Stack.
|
||||||
|
# You should not edit this file by hand.
|
||||||
|
# For more information, please see the documentation at:
|
||||||
|
# https://docs.haskellstack.org/en/stable/lock_files
|
||||||
|
|
||||||
|
packages:
|
||||||
|
- completed:
|
||||||
|
hackage: hoauth2-2.6.0@sha256:168321df73bf75dc7cdda8e72725e9f3f624a9776b1fe59ae46c29c45029dc5d,2262
|
||||||
|
pantry-tree:
|
||||||
|
sha256: 5d39759b171cfaaf5842069a5548c2c1a41c0978645d018da7df713a186192b5
|
||||||
|
size: 859
|
||||||
|
original:
|
||||||
|
hackage: hoauth2-2.6.0
|
||||||
|
snapshots:
|
||||||
|
- completed:
|
||||||
|
sha256: b77e2c2b7988ed34cd317c01eb1958a8b8c234c3cc17e44077616c212959bed0
|
||||||
|
size: 558756
|
||||||
|
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/12/9.yaml
|
||||||
|
original: nightly-2022-12-09
|
||||||
@ -1,11 +1,10 @@
|
|||||||
resolver: nightly-2022-12-09
|
resolver: nightly-2023-01-30
|
||||||
|
|
||||||
extra-deps:
|
extra-deps:
|
||||||
- hoauth2-2.6.0
|
- hoauth2-2.7.0
|
||||||
|
|
||||||
|
allow-newer-deps:
|
||||||
|
- hoauth2
|
||||||
# hoauth2 needs upper-bounds relaxed for
|
# hoauth2 needs upper-bounds relaxed for
|
||||||
#
|
- memory
|
||||||
# - memory-0.18.0
|
- text
|
||||||
# - text-2.0.1
|
|
||||||
#
|
|
||||||
allow-newer: true
|
|
||||||
|
|||||||
@ -5,43 +5,15 @@
|
|||||||
|
|
||||||
packages:
|
packages:
|
||||||
- completed:
|
- completed:
|
||||||
hackage: hoauth2-2.4.0@sha256:c2609ee4744dee10640b9d7d85d271bd8ef643d38b0bddd006cdbe2997582481,2814
|
hackage: hoauth2-2.7.0@sha256:34c5b82d49a814cfa214b65f5422fda876e38c1275504b574355cf5413e37138,2833
|
||||||
pantry-tree:
|
pantry-tree:
|
||||||
size: 594
|
sha256: f575d77978c823bedba13c67f7e31195da6c5543fbd9b35b9def225a8ace6833
|
||||||
sha256: 5e035c54476fbc89f11b8cd13dcd91f2cf2501d3b4276a1b39d1531d1487ade1
|
size: 996
|
||||||
original:
|
original:
|
||||||
hackage: hoauth2-2.4.0
|
hackage: hoauth2-2.7.0
|
||||||
- completed:
|
|
||||||
hackage: yesod-auth-1.6.11@sha256:602c0db6cc85cb7b4ad82970379e77e3dee650ab6f05d8d955c6fec7934c5f31,3054
|
|
||||||
pantry-tree:
|
|
||||||
size: 1013
|
|
||||||
sha256: 3c6076aa68d31b1f2c40f327bb11c7c7adf7c3ec0f8288ade092185b241c2451
|
|
||||||
original:
|
|
||||||
hackage: yesod-auth-1.6.11
|
|
||||||
- completed:
|
|
||||||
hackage: yesod-core-1.6.22.0@sha256:116c0c2013e81a5cd426ddeb94e07242f4b849a6e9d8a4aa02a2dae826c58086,8124
|
|
||||||
pantry-tree:
|
|
||||||
size: 5367
|
|
||||||
sha256: 61bbff374230df6c88f873bf24072760e9fbc2c5c1000870d20120d8d1028bba
|
|
||||||
original:
|
|
||||||
hackage: yesod-core-1.6.22.0
|
|
||||||
- completed:
|
|
||||||
hackage: yesod-form-1.7.0@sha256:fd857fb9ea4f5af8500ec8613aa026e3a478c874b93da9d8ab8f17f329ec8c9e,3387
|
|
||||||
pantry-tree:
|
|
||||||
size: 1729
|
|
||||||
sha256: 228cbf75994b694a05ecd413935fd3bd8c32d4a7f1b0b486777fd913a440cdbe
|
|
||||||
original:
|
|
||||||
hackage: yesod-form-1.7.0
|
|
||||||
- completed:
|
|
||||||
hackage: yesod-persistent-1.6.0.7@sha256:7ece60b1a1e0c9f56ec2f1cf67dd9d0c3962ccabc878b975bef7f743709d267d,1732
|
|
||||||
pantry-tree:
|
|
||||||
size: 497
|
|
||||||
sha256: 3778ef2964e1a3890afc22cc9124eacb40e64b62bed4983a85d3b99897f54c5c
|
|
||||||
original:
|
|
||||||
hackage: yesod-persistent-1.6.0.7
|
|
||||||
snapshots:
|
snapshots:
|
||||||
- completed:
|
- completed:
|
||||||
size: 520054
|
sha256: 09ac166bef7e4db4adb4830cf87b3ef4160477702c3da0765d9f7a8c2cffd446
|
||||||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/3/25.yaml
|
size: 596592
|
||||||
sha256: 2c84a2124de70525171f9f6dc92544658c5353e42084e08635b8513d1fa4e6fc
|
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2023/1/30.yaml
|
||||||
original: nightly-2022-03-25
|
original: nightly-2023-01-30
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
cabal-version: 1.18
|
cabal-version: 1.18
|
||||||
|
|
||||||
-- This file has been generated from package.yaml by hpack version 0.35.0.
|
-- This file has been generated from package.yaml by hpack version 0.35.1.
|
||||||
--
|
--
|
||||||
-- see: https://github.com/sol/hpack
|
-- see: https://github.com/sol/hpack
|
||||||
--
|
--
|
||||||
-- hash: 6ff32214308580349bea075f2eb01f97fc72598ea3e9a23f77a3e678d9c2c23a
|
-- hash: 2aa7c7881c27a03f22715aa6db358fc5fe466f5967a09741265bd0f7a999e2b1
|
||||||
|
|
||||||
name: yesod-auth-oauth2
|
name: yesod-auth-oauth2
|
||||||
version: 0.7.0.2
|
version: 0.7.0.3
|
||||||
synopsis: OAuth 2.0 authentication plugins
|
synopsis: OAuth 2.0 authentication plugins
|
||||||
description: Library to authenticate with OAuth 2.0 for Yesod web applications.
|
description: Library to authenticate with OAuth 2.0 for Yesod web applications.
|
||||||
category: Web
|
category: Web
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user