packages feed

oidc-client 0.5.0.0 → 0.5.1.0

raw patch · 5 files changed

+59/−12 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Web.OIDC.Client.Discovery: generateDiscoveryUrl :: IssuerLocation -> IO Request

Files

CHANGELOG.md view
@@ -1,5 +1,11 @@ # ChangeLog +## [0.5.1.0]+### Fixed+- fix: generate correct discovery url ([#39](https://github.com/krdlab/haskell-oidc-client/pull/39))+- Fix discovery URL generation ([#40](https://github.com/krdlab/haskell-oidc-client/pull/40))+    - Corrected more cases+ ## [0.5.0.0] ### Added - Add implicit id_token flow. See [#34](https://github.com/krdlab/haskell-oidc-client/pull/34).
oidc-client.cabal view
@@ -1,5 +1,5 @@ name:               oidc-client-version:            0.5.0.0+version:            0.5.1.0 synopsis:           OpenID Connect 1.0 library for RP homepage:           https://github.com/krdlab/haskell-oidc-client stability:          experimental@@ -71,6 +71,7 @@   main-is:              Spec.hs   other-modules:       Spec.Client+    , Spec.Client.Discovery     , Spec.Client.Internal      -- NOTE: The following modules are needed for using Web.OIDC.Client.Internal.
src/Web/OIDC/Client/Discovery.hs view
@@ -14,15 +14,18 @@     -- * OpenID Provider Configuration Information     , Provider(..)     , Configuration(..)++    -- * For testing+    , generateDiscoveryUrl     ) where  import           Control.Monad.Catch                (catch, throwM) import           Data.Aeson                         (eitherDecode)-import           Data.ByteString                    (append)+import           Data.ByteString                    (append, isSuffixOf) import           Data.Text                          (pack) import qualified Jose.Jwk                           as Jwk-import           Network.HTTP.Client                (Manager, httpLbs, path,-                                                     responseBody)+import           Network.HTTP.Client                (Manager, Request, httpLbs,+                                                     path, responseBody)  import           Web.OIDC.Client.Discovery.Issuers  (google) import           Web.OIDC.Client.Discovery.Provider (Configuration (..),@@ -46,12 +49,9 @@                 Left  err  -> throwM $ DiscoveryException ("Failed to decode JwkSet: " <> pack err)         Left  err -> throwM $ DiscoveryException ("Failed to decode configuration: " <> pack err)   where-    appendPath suffix req = req { path = path req `append` suffix }-     getConfiguration = do-        req <- parseUrl location-        let req' = appendPath "/.well-known/openid-configuration" req-        res <- httpLbs req' manager+        req <- generateDiscoveryUrl location+        res <- httpLbs req manager         return $ eitherDecode $ responseBody res      getJwkSetJson url = do@@ -60,3 +60,14 @@         return $ responseBody res      jwks j = Jwk.keys <$> eitherDecode j++generateDiscoveryUrl :: IssuerLocation -> IO Request+generateDiscoveryUrl location = do+    req <- parseUrl location+    return $ appendPath ".well-known/openid-configuration" req+  where+    appendPath suffix req =+        let p = path req+            p' = if "/" `isSuffixOf` p then p else p `append` "/"+        in+            req { path = p' `append` suffix }
test/Spec.hs view
@@ -1,8 +1,10 @@-import qualified Spec.Client          as Client-import qualified Spec.Client.Internal as Internal-import           Test.Hspec           (hspec)+import qualified Spec.Client           as Client+import qualified Spec.Client.Discovery as Discovery+import qualified Spec.Client.Internal  as Internal+import           Test.Hspec            (hspec)  main :: IO () main = hspec $ do     Client.tests+    Discovery.tests     Internal.tests
+ test/Spec/Client/Discovery.hs view
@@ -0,0 +1,27 @@+{-# OPTIONS_GHC -Wno-warnings-deprecations #-}+{-# LANGUAGE OverloadedStrings #-}+module Spec.Client.Discovery where++import           Network.HTTP.Client       (path)+import           Test.Hspec                (Spec, describe, it, shouldBe)+import           Web.OIDC.Client.Discovery (generateDiscoveryUrl)+++tests :: Spec+tests =+    describe "Discovery.generateDiscoveryUrl" $ do+        it "should return a valid URL" $ do+            url <- generateDiscoveryUrl "https://accounts.google.com"+            path url `shouldBe` "/.well-known/openid-configuration"++        it "should return a valid URL if the location has a trailing slash" $ do+            url <- generateDiscoveryUrl "https://accounts.google.com/"+            path url `shouldBe` "/.well-known/openid-configuration"++        it "should return a valid URL if the location has a path" $ do+            url <- generateDiscoveryUrl "https://login.microsoftonline.com/common/v2.0"+            path url `shouldBe` "/common/v2.0/.well-known/openid-configuration"++        it "should return a valid URL if the location has both path and trailing slash" $ do+            url <- generateDiscoveryUrl "https://login.microsoftonline.com/common/v2.0/"+            path url `shouldBe` "/common/v2.0/.well-known/openid-configuration"