Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Have the validation keys as an IORef #193

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dnikolovv
Copy link

This goes back to #153.

It is very limiting not being able to update the validation keys, as most auth providers (Cognito, Auth0, Firebase) use rotating keys.

This change makes it very straightforward to implement. I saw that there is a (stale?) PR referring to this issue (#169), but I find this approach much less invasive therefore I'm submitting a new one.

Example on how you could use this to implement rotating keys:

getConfig :: IO Config
getConfig = do
 -- ...
 jwtSettings <- initializeJWTSettings

 void . async $
   forever $ do
     newKeys <- getKeys
     writeIORef (validationKeys jwtSettings) newKeys
     threadDelay $ 1000 * 60000 * 60 -- 60 minutes
 -- ...

-- | An @aud@ predicate. The @aud@ is a string or URI that identifies the
-- intended recipient of the JWT.
, audienceMatches :: Jose.StringOrURI -> IsMatch
} deriving (Generic)

-- | A @JWTSettings@ where the audience always matches.
defaultJWTSettings :: Jose.JWK -> JWTSettings
defaultJWTSettings k = JWTSettings
defaultJWTSettings :: Jose.JWK -> IO JWTSettings
Copy link
Author

@dnikolovv dnikolovv Jun 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we could even omit the IO via unsafePerformIO to avoid forcing existing users change their code. It should be relatively safe as the only thing we're doing is create a new IORef.

This will make the changes even less invasive (or in most cases invisible).

I guess @jkarni @domenkozar or other maintainers should give their opinion on that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant