From df7e59c69629e872aee92b8694cef961a38f3b80 Mon Sep 17 00:00:00 2001 From: Fumiaki Kinoshita Date: Sat, 21 Sep 2019 20:30:11 +0900 Subject: [PATCH] api demo --- wai-middleware-webauthn/demo/Main.hs | 8 +++++++- wai-middleware-webauthn/demo/config.yaml | 4 +++- wai-middleware-webauthn/demo/demo.cabal | 1 + wai-middleware-webauthn/demo/index.html | 21 ++++++++++++++++++++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/wai-middleware-webauthn/demo/Main.hs b/wai-middleware-webauthn/demo/Main.hs index ad454ff..34a39bb 100644 --- a/wai-middleware-webauthn/demo/Main.hs +++ b/wai-middleware-webauthn/demo/Main.hs @@ -10,6 +10,7 @@ import Network.HTTP.Types import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.Yaml as Yaml +import qualified Data.Aeson as J import Paths_demo main :: IO () @@ -20,4 +21,9 @@ main = do pathCert <- getDataFileName "certificate.pem" pathKey <- getDataFileName "key.pem" runTLS (tlsSettings pathCert pathKey) (setPort 8080 defaultSettings) { settingsHTTP2Enabled = False } - $ mid $ \req sendResp -> sendResp $ responseFile status200 [] path Nothing + $ mid $ \req sendResp -> case pathInfo req of + [] -> sendResp $ responseFile status200 [] path Nothing + ["api"] -> case WebAuthn.requestIdentifier req of + Nothing -> sendResp $ responseLBS status401 [] "Authorisation required" + Just name -> sendResp $ responseLBS status200 [] $ J.encode name + _ -> sendResp $ responseLBS status404 [] "Not found" diff --git a/wai-middleware-webauthn/demo/config.yaml b/wai-middleware-webauthn/demo/config.yaml index 710a33e..a36b4db 100644 --- a/wai-middleware-webauthn/demo/config.yaml +++ b/wai-middleware-webauthn/demo/config.yaml @@ -1,4 +1,6 @@ origin: "https://localhost:8080" endpoint: "webauthn" authorisedKeys: - fumieval: {"credentialId":"0IMo2OFRmM903AGEP5/1u5eVGlcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==","publicKey":"pQECAyYgASFYICJwKPYkRYKWH6OIAjp+IDghFnl06S0iSGjxn/arBp0OIlggoJmTH1ZaVWCrn3A2b+wZx4/mVePRFowKujU5xXmafJY="} + fumieval: + credentialId: "0IMo2OFRmM903AGEP5/1u5eVGlcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==" + publicKey: "pQECAyYgASFYICJwKPYkRYKWH6OIAjp+IDghFnl06S0iSGjxn/arBp0OIlggoJmTH1ZaVWCrn3A2b+wZx4/mVePRFowKujU5xXmafJY=" diff --git a/wai-middleware-webauthn/demo/demo.cabal b/wai-middleware-webauthn/demo/demo.cabal index c7b84ec..e3ef3e1 100644 --- a/wai-middleware-webauthn/demo/demo.cabal +++ b/wai-middleware-webauthn/demo/demo.cabal @@ -28,6 +28,7 @@ executable demo , http-types , bytestring , yaml + , aeson -- hs-source-dirs: other-modules: Paths_demo default-language: Haskell2010 diff --git a/wai-middleware-webauthn/demo/index.html b/wai-middleware-webauthn/demo/index.html index 5be9873..1ee9dfe 100644 --- a/wai-middleware-webauthn/demo/index.html +++ b/wai-middleware-webauthn/demo/index.html @@ -18,9 +18,12 @@ +
+