flipped token encoding/decoding keys

This commit is contained in:
David Mosbach 2024-01-10 16:12:44 +00:00
parent c68bf943f3
commit 6e26ff0403

View File

@ -217,12 +217,12 @@ tokenEndpoint = provideToken
mkToken :: AuthState -> IO JWTWrapper mkToken :: AuthState -> IO JWTWrapper
mkToken state = do mkToken state = do
privateKey <- atomically $ readTVar state >>= return . privateKey pubKey <- atomically $ readTVar state >>= return . publicKey
now <- getCurrentTime now <- getCurrentTime
let let
lifetime = nominalDay / 4 -- TODO make configurable lifetime = nominalDay / 4 -- TODO make configurable
jwt = JWT "Oauth2MockServer" (lifetime `addUTCTime` now) jwt = JWT "Oauth2MockServer" (lifetime `addUTCTime` now)
encoded <- jwkEncode RSA_OAEP_256 A128GCM privateKey (Nested . Jwt . toStrict $ encode jwt) encoded <- jwkEncode RSA_OAEP_256 A128GCM pubKey (Nested . Jwt . toStrict $ encode jwt)
case encoded of case encoded of
Right (Jwt token) -> return $ JWTW (BS.unpack token) lifetime Right (Jwt token) -> return $ JWTW (BS.unpack token) lifetime
Left e -> error $ show e Left e -> error $ show e
@ -265,8 +265,8 @@ userEndpoint = handleUserData
decodeToken :: Text -> AuthState -> IO (Either JwtError JwtContent) decodeToken :: Text -> AuthState -> IO (Either JwtError JwtContent)
decodeToken token state = do decodeToken token state = do
pubKey <- atomically $ readTVar state >>= return . publicKey prKey <- atomically $ readTVar state >>= return . privateKey
jwkDecode pubKey $ encodeUtf8 token jwkDecode prKey $ encodeUtf8 token
userListEndpoint :: forall user userData . UserData user userData => AuthServer (UserList userData) userListEndpoint :: forall user userData . UserData user userData => AuthServer (UserList userData)
userListEndpoint = handleUserData userListEndpoint = handleUserData