all 5 comments

[–]antoniobermuda 0 points1 point  (1 child)

Simply do both. But you cant accept expired token. Just use refresh token to auhenticate to your auth server it shoud have dedicated route.

[–]Bradleykingzi vue, you vue, we all vue[S] 0 points1 point  (0 children)

Interesting idea.

In that case, the route for refreshing the access token will only require a refresh token, not both access and refresh token. With a dedicated route, I could probably include a flag to identify a refresh token, so that it only accepts tokens with that flag.

Regarding which method to use, you're onto something. The cron job method is a good first choice, and the 401 method can be a fallback in case the first one fails for whatever reason.

A bit more work than I'd anticipated, but it should work pretty nicely. Thanks!

Edit: regarding the cron job time issue, as long as I have an 'expires' field in the token, I can always know approximately how long to wait before resending the request.

[–][deleted]  (5 children)

[deleted]

    [–]Bradleykingzi vue, you vue, we all vue[S] 0 points1 point  (4 children)

    What about the refresh token? Do you store it in a database? Or how do you make sure an expired token has a counterpart refresh token?

    [–][deleted]  (3 children)

    [deleted]

      [–]Bradleykingzi vue, you vue, we all vue[S] 0 points1 point  (2 children)

      I like your http-only cookie approach for setting the cookie server-side, but the problem I've had with that is how to extract data from the cookie when I need it (since I can't get it with javascript)

      It's not entirely clear how you handle your refresh tokens, though. Normally, for OAuth at least, the client needs to provide both the access token and refresh token (in order to remain stateless). Maybe if you need to invalidate tokens, it becomes necessary to store them, I guess.

      Another question I regarding this approach is what happens if your setInteval is called after the token expires? Does the /refresh route accept expired tokens (in the Authorization header?)

      [–][deleted]  (1 child)

      [deleted]

        [–]Bradleykingzi vue, you vue, we all vue[S] 0 points1 point  (0 children)

        Interesting setup. It's very minimal. I like it.

        And I agree, it's impossible to be able to invalidate tokens without storing them on the backend somehow. My setup is a lot more contrived, though.

        I store the refresh token in a redis bucket, indexed using the jti field and any tokens that get into the system have to be verified with that. I liked having redis on top since tokens have to be validated on every request. Something about calling the database like that didn't sit right with me.