Saleor: Authorization token doesn't check expiration date

Created on 2 Jan 2020  路  16Comments  路  Source: mirumee/saleor

Steps to reproduce the problem

  1. Create JWT token using tokenCreate mutation
  2. check expiration date
  3. use token after token expires
backlog bug

Most helpful comment

After further investigation, we concluded that the entire JWT authentication implementation in Saleor should be reworked. Here is the desired flow (roughly):

  • tokenCreate mutation generates accessToken, refreshToken and sets an HTTP-only cookie with the refreshToken.
  • accessToken is stored in the client app in memory (not in local storage as it is now),
  • the client app can refresh the accessToken with a mutation that reads the refreshToken from the cookie
  • Saleor comes with a recommended configuration where accessToken expires after 5 minutes

After investigating how refresh tokens work in the django-graphql-jwt we also concluded that it doesn't really meet our needs (it's really well described in this issue - https://github.com/flavors/django-graphql-jwt/issues/159). Adjusting it would require too many changes in the original library (by copying its parts to Saleor), so the idea is to implement these mutations entirely in Saleor. We can try to reuse parts of the library, but if it makes the development harder, then we can reimplement it on our side.

All 16 comments

Hi! By default the tokens don't expire, refer to https://django-graphql-jwt.domake.io/en/latest/settings.html#token-expiration.

@NyanKiyoshi you're right, my bad, in that case I propose to add if ... else ... statement where
we check if debug false set expiration_check to True

added in
#5076

Is this environment variable in the correct location? Only when moving it to the GRAPHQL_JWT dictionary I've got the token to expire.

Yes that should in the GRAPHQL_JWT and not in the root of settings.py

After further investigation, we concluded that the entire JWT authentication implementation in Saleor should be reworked. Here is the desired flow (roughly):

  • tokenCreate mutation generates accessToken, refreshToken and sets an HTTP-only cookie with the refreshToken.
  • accessToken is stored in the client app in memory (not in local storage as it is now),
  • the client app can refresh the accessToken with a mutation that reads the refreshToken from the cookie
  • Saleor comes with a recommended configuration where accessToken expires after 5 minutes

After investigating how refresh tokens work in the django-graphql-jwt we also concluded that it doesn't really meet our needs (it's really well described in this issue - https://github.com/flavors/django-graphql-jwt/issues/159). Adjusting it would require too many changes in the original library (by copying its parts to Saleor), so the idea is to implement these mutations entirely in Saleor. We can try to reuse parts of the library, but if it makes the development harder, then we can reimplement it on our side.

@maarcingebala do you think it will be squeezed into the 2.11 along with permission management, or should we not expect these changes too soon?

Thank you for your development efforts, love the project

We're now working on 2.10 and planning to release it in about two weeks for today. We haven't yet planned the exact scope of 2.11, but this ticket should have high priority and I'll try to push it once we have a planning meeting with the team. Thanks for reminding me.

This is the one only thing keeping from going all out on saleor. I'm waiting for this. Thank you

@maarcingebala isn't this already fixed in 2.10?

We haven't touched it, it's planned for 2.11.

OK, so this is partially fixed, but we also want to rework a large part of the entire JWT implementation (maybe it should be a separate issue - https://github.com/mirumee/saleor/issues/5128#issuecomment-580693586).

Yeah, I think opening a separate issue would be better as this issues is fixed.

JWT auth layer rebuilt in #5734. So this issue is not valid anymore

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lewis617 picture lewis617  路  3Comments

damianarechar picture damianarechar  路  3Comments

timuric picture timuric  路  3Comments

tanvirraj picture tanvirraj  路  3Comments

mad-anne picture mad-anne  路  3Comments