Feature/6222 - Endpoint /api/v1/users/sign_out revokes access token and refresh token on request#6241
Conversation
|
👀 |
| let(:casa_org) { create(:casa_org) } | ||
| let(:volunteer) { create(:volunteer, casa_org: casa_org) } | ||
| let(:api_credential) { create(:api_credential, user: volunteer) } | ||
| let(:refresh_token) { api_credential.return_new_refresh_token![:refresh_token] } |
There was a problem hiding this comment.
Er, is this regenerating a refresh token a 2nd time?
There was a problem hiding this comment.
I think when you create the api credential table for the first time, the token digest fields are nil - at least in dev environment and so that is why I created the seed file to populate them.
I also need the plain text refresh token to be passed in the authorization header for the sign out.
There was a problem hiding this comment.
Sure thing, will make note this for future issues (Keep unresolved for now)
There was a problem hiding this comment.
Looks good so far, as mentioned on the issues acceptance criteria and in our discussions. Still need to...
- Add the
sign_inroute toroutes.rb(session#destroy) - Add a destroy function to the
sessions_controller.rbusing therevocationfunction(s) helper you made - Address comments, test route with whatever you'd like to use though my preference is curl, then should lgtm 😎
No but can defiantly make one. This is the current AccountScreen with a Sign-out button. Current behaviour is just a console log |
ok I got it. I can work on this issue. Let me know if you havn't already and I will create an issue for it. |
Thanks, all good, here's the issue for end-to-end implementation. |
What github issue is this PR for, if any?
Resolves #6222
What changed, and why?
Added /api/v1/users/sign_out endpoint so both the access and refresh tokens for that user is cleared from the api_credentials table and set to nil.
Why?: for added security - tokens should be removed from api_credentials table because user is no longer signed in.
How is this tested? (please write tests!) 💖💪
Token Destroyer Helper Function tests (2 in total)→ spec/models/api_credential_spec.rbSign Out Request Test for 200 and 401 Response Cases→ spec/requests/api/v1/users/sessions_spec.rbScreenshots please :)
Testing sign out with postman on localhost
Steps:

First we sign in to fetch the refresh token
Lastly we sign out and pass in refresh token in the request authorization header
Feelings gif (optional)