Skip to content

Set up user identity and JWT for native users #84

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

Merged
merged 11 commits into from
Dec 16, 2023
Merged

Conversation

taesungh
Copy link
Member

@taesungh taesungh commented Dec 15, 2023

Include the user identity code from last year to provide JWTs when completing SAML authentication.
The full guest authentication flow will come separately with #68, but the user identity foundation is provided here, e.g. the GuestUser model.

Closes #69.

Changes

  • Import user and user identity from last year
  • Move JWT_SECRET check to index.py
  • Resolve type errors w/ NativeUser, EmailStr
    • Ignore call-arg error when calling super constructor
    • EmailStr no longer needs to be explicitly constructed
  • Resolve pydantic deprecation warnings
    • Replace dict with model_dump and parse_obj with model_validate
  • Fix uid scoping when local part contains dot
  • Incorporate user identity with SAML authentication
    • Provide user identity cookie when authenticating with SAML ACS
    • Rename hackuci_auth to irvinehacks_auth
  • Improve type annotations in user/user_identity
    • Use Annotated for Cookie and Union instead of Optional
  • Fix model issue with IdentityResponse for user
  • Include note in API README about JWT_KEY
  • Rename log_out to logout for consistency
  • Add Pydantic mypy plugin to fix submodel call-arg

Testing

Staging subdomain was manually assigned to the preview deployment. Confirmed SAML flow works and user identity cookie is provided which is properly consumed by /api/user/me endpoint.

- Import `user_identity` auth, `user` router, and `user_record` util,
  and associated tests from last year's HackAtUCI/HackUCI-Site
- Install python-jose[cryptography]
- Add user router to app
- Ignore call-arg error when calling super constructor
- `EmailStr` no longer needs to be explicitly constructed
- Replace `dict` with `model_dump` and `parse_obj` with `model_validate`
- Provide user identity cookie when authenticating with SAML ACS
- Rename `hackuci_auth` to `irvinehacks_auth`
- Use `Annotated` for `Cookie` and `Union` instead of `Optional`
- `Optional` fields are no longer not required in Pydantic V2 models
- Add unit test for `/user/me` endpoint
@taesungh taesungh requested a review from samderanova December 15, 2023 09:43
Copy link
Contributor

github-actions bot commented Dec 15, 2023

Deploy preview for irvinehacks-site-2024-sanity ready!

Name Sanity Studio
Preview Visit Preview
Commit aded12e

Copy link
Contributor

github-actions bot commented Dec 15, 2023

Deploy preview for irvinehacks-site-2024 ready!

Name IrvineHacks 2024 Site
Preview Visit Preview
Commit aded12e

Copy link
Contributor

@samderanova samderanova left a comment

Choose a reason for hiding this comment

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

Good work on this! Thankfully, stubs exist for python-jose already.

Copy link
Contributor

@samderanova samderanova left a comment

Choose a reason for hiding this comment

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

A few nitpicks addressed above:

@taesungh taesungh changed the title Setup/user identity Set up user identity and JWT for native users Dec 15, 2023
- Add `pydantic.mypy` plugin to generate signature for `Model.__init__`
- Do not enable `init_forbid_extra` option
  - This will type `super().__init__` with an extra `kwargs: Any`
  - Thus the type ignore in `NativeUser` can be removed
@samderanova samderanova self-requested a review December 15, 2023 19:49
@taesungh taesungh requested a review from rileysw December 15, 2023 21:24
@samderanova
Copy link
Contributor

Please squash merge.

@taesungh taesungh merged commit 7f63eb8 into main Dec 16, 2023
@taesungh taesungh deleted the setup/user-identity branch December 17, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set up JWTs
3 participants