Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/72 authentication frameworkgoogle #104

Merged
merged 26 commits into from
Mar 18, 2024

Conversation

Ahydul
Copy link
Contributor

@Ahydul Ahydul commented Mar 16, 2024

Refactored authentication system to use Djoser, a authentication library compatible with Rest Framework.
The following working endpoints were introduced:

  • get /api/auth/users/me/
    Needs: header: Authorization=JWT access_token
    Action: List the user with the associated access_token

  • get: /api/auth/users/
    Needs: header: Authorization=JWT access_token
    Action: List the users if the access_token's user has permission

  • post: /api/auth/users/
    Needs: Add parameters
    Action: Create user

  • post /api/auth/jwt/create
    Needs: Add parameters
    Action: Create access_token and refresh_token

  • post /api/auth/jwt/refresh
    Needs: add refresh_token
    Action: Create new access_token and refresh_token

  • post /api/auth/blacklist
    Needs: Add refresh_token
    Action: Blacklist refrest_token, needed for logout.

    Research "2–4) Logging out and blacklisting tokens" in for more information in the react implementation of logout

  • get /api/auth/o/google-oauth2/?redirect_uri=http://127.0.0.1:8000/api/redirect-social/
    Action: Returns authorization_url which directs to google login.

  • get authoriation_url
    Action: Loging in redirects to /api/redirect-social which returns a 'code' and a 'state'

  • post /api/auth/o/google-oauth2/?state=state&code=code
    Needs: Returns access, refresh and user
    Action: The user created is not enabled because it lacks id_number. To activate it see next post.

  • post /api/auth/activate/
    Needs: header: Authorization=JWT access_token
    Action: Activate the user associated to the access_token if it has an id_number

This PR changes the User model to use the default Django user as base.

@Ahydul Ahydul self-assigned this Mar 16, 2024
@Ahydul Ahydul linked an issue Mar 16, 2024 that may be closed by this pull request
@Ahydul
Copy link
Contributor Author

Ahydul commented Mar 17, 2024

As per request from some people I'm going to explain how to test the PR.

I've used the extension ModHeader to introduce the header Authorization. You simply add the header, the name should be Authorization and the value should be "JWT access_token" (without the ". The token is created in /api/auth/jwt/create).

To test each endpoint, simply search it. If it's a post action, introduce the parameters it needs if it asks for them and click post.

The endpoints may ask for the authorization header. Make sure the Authorization header is only used when needed, it may break other websites.

Copy link
Contributor

@auroranavas auroranavas left a comment

Choose a reason for hiding this comment

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

Please add all the necessary modules to requirements.txt

image

@Ahydul Ahydul changed the base branch from main to develop March 18, 2024 11:35
Copy link
Contributor

@auroranavas auroranavas left a comment

Choose a reason for hiding this comment

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

I thoroughly tested every endpoint, both for a google account and for a regular account. All the test cases worked.

This looks like it took a lot of effort to implement. I sincerely congratulate you for your work.

Copy link
Contributor

@pabpercab1 pabpercab1 left a comment

Choose a reason for hiding this comment

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

You did a great job with the authentication framework. Now is working as expected, and you fulfilled all the requirements. Congratulations!

@pabpercab1 pabpercab1 added the enhancement New feature or request label Mar 18, 2024
@pabpercab1 pabpercab1 added this to the Sprint 2 milestone Mar 18, 2024
@JuanluRM JuanluRM self-requested a review March 18, 2024 23:02
Copy link
Contributor

@JuanluRM JuanluRM left a comment

Choose a reason for hiding this comment

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

This issue was a huge payload and your work was superb, congratulations.

@JuanluRM JuanluRM merged commit 691ac28 into develop Mar 18, 2024
6 checks passed
@JuanluRM JuanluRM deleted the feature/72-authentication-frameworkgoogle branch March 18, 2024 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Authentication Framework+Google
4 participants