Skip to content

Commit

Permalink
make port optional
Browse files Browse the repository at this point in the history
  • Loading branch information
fumieval committed Nov 22, 2019
1 parent 9e2ba0e commit 74c4cd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Web/WebAuthn/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ instance FromJSON WebAuthnType where
data Origin = Origin
{ originScheme :: Text
, originHost :: Text
, originPort :: Int
, originPort :: Maybe Int
}
deriving (Show, Eq, Ord)

Expand All @@ -107,9 +107,11 @@ defaultRelyingParty orig = RelyingParty orig (encodeUtf8 $ originHost orig) Fals
instance FromJSON Origin where
parseJSON = withText "Origin" $ \str -> case T.break (==':') str of
(sch, url) -> case T.break (==':') $ T.drop 3 url of
(host, portPath) -> case T.decimal $ T.drop 1 portPath of
Left e -> fail e
Right (port, _) -> pure $ Origin sch host port
(host, portStr)
| T.null portStr -> pure $ Origin sch host Nothing
| otherwise -> case T.decimal $ T.drop 1 portStr of
Left e -> fail e
Right (port, _) -> pure $ Origin sch host $ Just port

data AuthenticatorData = AuthenticatorData
{ rpIdHash :: Digest SHA256
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defaultConfig :: a -> Config a
defaultConfig a = Config
{ handler = a
, endpoint = "webauthn"
, origin = Origin "https" "localhost" 8080
, origin = Origin "https" "localhost" (Just 8080)
, timeout = 86400
}

Expand Down

0 comments on commit 74c4cd1

Please sign in to comment.