diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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).
diff --git a/oidc-client.cabal b/oidc-client.cabal
--- a/oidc-client.cabal
+++ b/oidc-client.cabal
@@ -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.
diff --git a/src/Web/OIDC/Client/Discovery.hs b/src/Web/OIDC/Client/Discovery.hs
--- a/src/Web/OIDC/Client/Discovery.hs
+++ b/src/Web/OIDC/Client/Discovery.hs
@@ -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 }
diff --git a/test/Spec.hs b/test/Spec.hs
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -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
diff --git a/test/Spec/Client/Discovery.hs b/test/Spec/Client/Discovery.hs
new file mode 100644
--- /dev/null
+++ b/test/Spec/Client/Discovery.hs
@@ -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"
