From 3a4e1a6632e73a64b98c0b3dbb9dec080cc2ba88 Mon Sep 17 00:00:00 2001 From: "William R. Arellano" Date: Tue, 31 Oct 2023 11:43:52 -0500 Subject: [PATCH] refactor code --- src/Yesod/Auth/OAuth2/Dispatch.hs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Yesod/Auth/OAuth2/Dispatch.hs b/src/Yesod/Auth/OAuth2/Dispatch.hs index 7ded8ca..6e522f0 100644 --- a/src/Yesod/Auth/OAuth2/Dispatch.hs +++ b/src/Yesod/Auth/OAuth2/Dispatch.hs @@ -105,18 +105,17 @@ withCallbackAndState -> Text -> m OAuth2 withCallbackAndState name oauth2 csrf = do - callback <- - case oauth2RedirectUri oauth2 of - Just uri -> pure uri - Nothing -> do - uri <- ($ PluginR name ["callback"]) <$> getParentUrlRender - maybe (throwError $ InvalidCallbackUri uri) pure $ fromText uri + callback <- maybe uriFromPlugin pure $ oauth2RedirectUri oauth2 pure oauth2 { oauth2RedirectUri = Just callback , oauth2AuthorizeEndpoint = oauth2AuthorizeEndpoint oauth2 `withQuery` [("state", encodeUtf8 csrf)] } + where + uriFromPlugin = do + uri <- ($ PluginR name ["callback"]) <$> getParentUrlRender + maybe (throwError $ InvalidCallbackUri uri) pure $ fromText uri getParentUrlRender :: MonadHandler m => m (Route (SubHandlerSite m) -> Text) getParentUrlRender = (.) <$> getUrlRender <*> getRouteToParent