You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This endpoint should use the new api_jwt_auth from #2959
The only thing this endpoint needs to do is a simple update on the expires_at timestamp in the user token session. This should use the same/similar logic to how we set the expires_at in the api_jwt_auth.py code.
You can fetch the current user token session by doing api_jwt_auth.current_user
NOTE: It will seem a bit odd, but you must do db_session.add(user_token_session) in the endpoint in order to actually modify it. This has to do with some complex under-the-hood details on how the DB sessions work (in short - the DB session the API uses and that auth uses is different so we need to make the API one aware of it).
Request
There is no request body for this endpoint, the auth token itself is handled by connecting auth to the endpoint
Response
The response is also very simple, we just want a very basic Response Schema without a relevant data object - see what the Healthcheck endpoint does. We really just want to return a message like Token refreshed when successful.
Note on testing
For unit tests, you can make a valid token by doing something like:
user=UserFactory.create()
token, _=create_jwt_for_user(user, db_session)
db_session.commit() # need to commit here to push the session to the DB# then freely use the token to call the endpoint
Acceptance criteria
Endpoint created
Token expires_at updated and validated in tests
Basic tests (endpoint gives auth errors if token already expired / isn't valid - which is implemented in the auth logic itself)
The text was updated successfully, but these errors were encountered:
## Summary
Fixes #{[2817](#2817)}
### Time to review: __5 mins__
## Changes proposed
Added POST endpoint `token/refresh`
Added `UserTokenRefreshResponseSchema`
Added reusable func `refresh_token_expiration`
Added 2 tests. For success case and case when token was expired
---------
Co-authored-by: nava-platform-bot <[email protected]>
Summary
Create a new endpoint that refreshes a token.
This endpoint should use the new
api_jwt_auth
from #2959The only thing this endpoint needs to do is a simple update on the
expires_at
timestamp in the user token session. This should use the same/similar logic to how we set the expires_at in the api_jwt_auth.py code.You can fetch the current user token session by doing
api_jwt_auth.current_user
NOTE: It will seem a bit odd, but you must do
db_session.add(user_token_session)
in the endpoint in order to actually modify it. This has to do with some complex under-the-hood details on how the DB sessions work (in short - the DB session the API uses and that auth uses is different so we need to make the API one aware of it).Request
There is no request body for this endpoint, the auth token itself is handled by connecting auth to the endpoint
Response
The response is also very simple, we just want a very basic Response Schema without a relevant data object - see what the Healthcheck endpoint does. We really just want to return a message like
Token refreshed
when successful.Note on testing
For unit tests, you can make a valid token by doing something like:
Acceptance criteria
The text was updated successfully, but these errors were encountered: