Skip to content

JWT Setup for Authentication - ios App feature#4901

Merged
FireLemons merged 10 commits intorubyforgood:mainfrom
xihai01:devise-jwt
Jun 28, 2023
Merged

JWT Setup for Authentication - ios App feature#4901
FireLemons merged 10 commits intorubyforgood:mainfrom
xihai01:devise-jwt

Conversation

@xihai01
Copy link
Copy Markdown
Collaborator

@xihai01 xihai01 commented Jun 21, 2023

What github issue is this PR for, if any?

This PR will set up the JWT authentication as part of the ios app codethechange is building.
It isn't linked to any issue in this repo - we forked a copy of this repo and are working on that forked copy.
Now we want to merge what we have done for the authentication.

What changed, and why?

Set up JWT with Devise.
I had to extend Devise sessions controller's create action to return a custom response for JSON requests.
I also extend respond_to_on_destroy method so sign out responds in json.
Additionally, I had to modify the accessible module so JSON requests don't get redirected to the root path.

How is this tested? (please write tests!) 💖💪

I created request specs for good/bad login to verify correct headers were sent (e.x authorization, content-type...etc) and also JSON data.
I also made specs for the sign out route -> testing JWT is moved to denylist and a 200 response.
Postman was used to make changes (i.e unassign a case assignment) in the portal provided a JWT was present.
I also did a live test where I ran the rails server on a ngrok tunnel and frontend app using expo go side by side.
See screenshots below.

Screenshots please :)

Live test using Ngrok and my android phone running the frontend with Expo go.

Screenshot from 2023-05-09 15-30-18

Postman: Success login means auth JWT in header

Screenshot from 2023-05-09 15-44-40
Screenshot from 2023-05-09 15-45-05

Postman: Failed login means auth JWT not in header

Screenshot from 2023-05-09 15-45-22
Screenshot from 2023-05-09 15-45-31

Postman: Unassign a case assignment using auth token passed in request header

Screenshot from 2023-05-09 17-12-06

Postman: Unassign a case assignment with no auth token

Screenshot from 2023-05-09 17-12-28

Postman: Sign out returns 200 response + JWT is moved to denylist

Screenshot from 2023-05-10 18-27-39
Screenshot from 2023-05-10 18-27-22

Feedback please? (optional)

We are very interested in your feedback! Please give us some :) https://forms.gle/1D5ACNgTs2u9gSdh9

@xihai01 xihai01 added the codethechange for codethechange developers label Jun 21, 2023
@xihai01 xihai01 requested a review from compwron as a code owner June 21, 2023 20:46
@xihai01 xihai01 self-assigned this Jun 21, 2023
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file ruby Pull requests that update Ruby code Tests! 🎉💖👏 labels Jun 21, 2023
@xihai01 xihai01 requested review from 7riumph and michaelruhl June 22, 2023 19:01
Copy link
Copy Markdown
Collaborator

@compwron compwron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable. :) @FireLemons how does it look to you?

@FireLemons FireLemons merged commit fce43a9 into rubyforgood:main Jun 28, 2023
@FireLemons
Copy link
Copy Markdown
Collaborator

🥇

compwron added a commit that referenced this pull request Jul 1, 2023
This reverts commit fce43a9, reversing
changes made to 79a6caf.
compwron added a commit that referenced this pull request Jul 1, 2023
* Revert "Merge pull request #4901 from xihai01/devise-jwt"

This reverts commit fce43a9, reversing
changes made to 79a6caf.

* bundle exec standardrb --fix

* mailer test oops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codethechange for codethechange developers dependencies Pull requests that update a dependency file ruby Pull requests that update Ruby code Tests! 🎉💖👏

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants