use case to avoid getParentUrlRender

This commit is contained in:
William R. Arellano 2023-10-31 11:38:51 -05:00
parent d379afc54b
commit 7f4030feda

View File

@ -12,7 +12,6 @@ module Yesod.Auth.OAuth2.Dispatch
, dispatchAuthRequest , dispatchAuthRequest
) where ) where
import Control.Applicative ((<|>))
import Control.Monad (unless) import Control.Monad (unless)
import Control.Monad.Except (MonadError (..)) import Control.Monad.Except (MonadError (..))
import Data.Text (Text) import Data.Text (Text)
@ -106,11 +105,15 @@ withCallbackAndState
-> Text -> Text
-> m OAuth2 -> m OAuth2
withCallbackAndState name oauth2 csrf = do withCallbackAndState name oauth2 csrf = do
uri <- ($ PluginR name ["callback"]) <$> getParentUrlRender callback <-
callback <- maybe (throwError $ InvalidCallbackUri uri) pure $ fromText uri case oauth2RedirectUri oauth2 of
Just uri -> pure uri
Nothing -> do
uri <- ($ PluginR name ["callback"]) <$> getParentUrlRender
maybe (throwError $ InvalidCallbackUri uri) pure $ fromText uri
pure pure
oauth2 oauth2
{ oauth2RedirectUri = (oauth2RedirectUri oauth2) <|> Just callback { oauth2RedirectUri = Just callback
, oauth2AuthorizeEndpoint = , oauth2AuthorizeEndpoint =
oauth2AuthorizeEndpoint oauth2 `withQuery` [("state", encodeUtf8 csrf)] oauth2AuthorizeEndpoint oauth2 `withQuery` [("state", encodeUtf8 csrf)]
} }