gardner / react-oauth2-pkce

React auth provider that works with AWS cognito PKCE🛡️🔒
49 stars 57 forks source link

feat: refresh token #1

Closed ronderksen closed 4 years ago

ronderksen commented 4 years ago

I'm working on a project where the oauth server returns a refresh_token and expires_in time. With this PR, a timeout is set when the original token is set. I still have to test it to make sure this works as expected, but I wanted to open a draft PR for early feedback :).

gardner commented 4 years ago

This looks great. How does it test?

ronderksen commented 4 years ago

I had to make some changes to the original setup, but it now refreshes the token automatically, if the AuthService is initiated with autoRefresh: true. There's also an option to give an amount of slack to the timeout, so that if the OAuth server returns an expires_in of X, then the timeout is triggered at X-refreshSlack (to make sure you get a token before the previous token expires).

ronderksen commented 4 years ago

I can add some unit tests sometime later this week, if you want.

ronderksen commented 4 years ago

Thanks for merging! Can you create a new npm version?

gardner commented 4 years ago

New npm version posted: 1.0.5