Skip to content

SAML 2.0 Compliance#256

Merged
naasanov merged 24 commits intomainfrom
arnav/saml-2.0-compliance
Mar 29, 2026
Merged

SAML 2.0 Compliance#256
naasanov merged 24 commits intomainfrom
arnav/saml-2.0-compliance

Conversation

@aLEGEND21
Copy link
Copy Markdown
Collaborator

Motivation

The existing SAML IdP needs to output the same attributes as the Onyen SSO IdP so that it could be mocked for testing. Additionally, users need to be authenticated by role and the entire auth flow should be linked to the backend so that the access and refresh token exchange can be successful.

Changes

  • Updated the test IdP to output the attributes listed in the TDD
  • Created several test users for the test IdP
  • Developed a separate credentials-based auth flow for police
  • Handled role-based auth where the frontend collects the user's role and passes it off to the backend upon successful sign-in
  • Connected the frontend auth to the backend routes
  • Updated the auth-test frontend routes to have buttons to test token refresh logic

Closes #201

MatthewBarghout and others added 8 commits February 27, 2026 14:01
* Implemented changes

* Fixes

* Fixes

* Fixes

* Fixes

* chore: fix ruff check

---------

Co-authored-by: Nicolas Asanov <nicolas.a.asanov@gmail.com>
* feat: Add test SAML IdP container to dev environment

* fix: Update apiClient to only import authOptions in server context

* feat: Add SAML authentication to frontend

* chore: Document SAML dev setup

* chore: Add env var to determine if unencrypted assertions are allowed

* feat: Automatically generate SAML certs in dev container

* feat: Hardcode dev SAML cert in env template

* chore: Re-add refresh token logic to NextAuth config

* feat: Add error handling for SAML cert loading

* chore: Improve error handling for SAML login callback

* chore: Ignore certs directory in frontend

* chore: Add default credentials for dev SAML IdP to README
@aLEGEND21
Copy link
Copy Markdown
Collaborator Author

Note that NextAuth is used to retrieve the session and instead of using providers, there are server routes that handle SAML and credentials validation that directly encode the JWT session. This is because the http-only cookie for the refresh token could not be set from within the providers' authorize functions since we don't have access to the NextResponse object from there, so we can't call res.cookies.set(...) to set the http-only cookie.

@aLEGEND21 aLEGEND21 requested a review from naasanov March 12, 2026 22:33
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 12, 2026

Test Results Summary

508 tests  +44   508 ✅ +44   36s ⏱️ +4s
  1 suites ± 0     0 💤 ± 0 
  1 files   ± 0     0 ❌ ± 0 

Results for commit ca2ac85. ± Comparison against base commit 8600d20.

♻️ This comment has been updated with latest results.

@naasanov naasanov changed the base branch from main to feature/saml-auth March 13, 2026 01:52
@naasanov naasanov changed the base branch from feature/saml-auth to main March 13, 2026 01:59
@naasanov naasanov changed the base branch from main to feature/saml-auth March 13, 2026 02:15
@naasanov naasanov changed the base branch from feature/saml-auth to main March 13, 2026 02:21
Copy link
Copy Markdown
Collaborator

@naasanov naasanov left a comment

Choose a reason for hiding this comment

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

Of the stuff that exists, it looks great. Just need to DRY some stuff up and keep to codebase conventions.

However, theres a couple things missing. The goal of this ticket is to get auth hooked up end to end, so we need login pages/buttons/flows for all roles on their pages. It should look very close to the final project in regards to auth.

Ideally a student/admin would navigate to any of their pages, and
if not signed in -> kicks them straight to IdP to sign in (or have a simple landing page similar to canvas if necessary)
if signed in -> automatically load whatever page they wanted

We also need a simple police login page that hooks into the flow, also kicking them to the login page if not signed in.

The logout button in the header should also work as intended.

Comment thread frontend/src/app/api/auth/login/saml/route.ts Outdated
Comment thread frontend/src/app/api/auth/login/saml/route.ts Outdated
Comment thread .devcontainer/saml-idp/authsources.php Outdated
Comment thread frontend/src/app/api/auth/login/saml/route.ts
Comment thread frontend/src/app/api/auth/police/login/route.ts Outdated
Comment thread frontend/src/app/api/auth/police/login/route.ts Outdated
Comment thread README.md Outdated
@aLEGEND21 aLEGEND21 requested a review from naasanov March 18, 2026 02:47
Copy link
Copy Markdown
Collaborator

@naasanov naasanov left a comment

Choose a reason for hiding this comment

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

Some fetches fail because they are still using the mock client (confirmed for student dashboard, may be true for others). Since this is meant to be the final iteration of auth feature, please go through and make sure all queries are working.

Also a couple small code comments

A couple small code comments.

Comment thread frontend/src/proxy.ts Outdated
Comment thread frontend/src/proxy.ts Outdated
Comment thread frontend/src/lib/api/auth/auth.types.ts Outdated
Comment thread frontend/src/lib/api/auth/auth.service.ts Outdated
@aLEGEND21
Copy link
Copy Markdown
Collaborator Author

Removed useRole + RoleProvider + RoleContext since we're no longer mocking the role and instead accessing it off of session. useRole could technically have stayed but it was a thin wrapper that just returned session.role which can be accessed via the useSession hook.

Copy link
Copy Markdown
Collaborator

@naasanov naasanov left a comment

Choose a reason for hiding this comment

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

Looks great, just waiting on merge conflicts

@aLEGEND21
Copy link
Copy Markdown
Collaborator Author

Merge conflicts have been resolved

@aLEGEND21 aLEGEND21 requested a review from naasanov March 28, 2026 20:06
Copy link
Copy Markdown
Collaborator

@naasanov naasanov left a comment

Choose a reason for hiding this comment

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

LGTM

@naasanov naasanov merged commit 208f717 into main Mar 29, 2026
3 checks passed
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.

SAML 2.0 Compliance

3 participants