Skip to content

Add OIDC login#154

Merged
ajkyffin merged 22 commits intomainfrom
oidc
Dec 9, 2025
Merged

Add OIDC login#154
ajkyffin merged 22 commits intomainfrom
oidc

Conversation

@ajkyffin
Copy link
Copy Markdown
Member

@ajkyffin ajkyffin commented Oct 8, 2025

This PR will close #135

Description

Adds endpoints for OIDC authentication

Testing Instructions

  • Review code
  • Check GitHub Actions build
  • Review changes to test coverage
  • Test using PKCE
  • Test using a client_secret

@louise-davies
Copy link
Copy Markdown
Member

louise-davies commented Oct 9, 2025

When trying to run this branch in Docker (either via the image the CI built and uploaded to Harbor or building locally) I get an import error:

ImportError: cannot import name 'OIDC_ICATAuthenticator' from
'scigateway_auth.src.authentication'
(/app/scigateway_auth/src/authentication.py)

EDIT:
64a4b9a - this refactor wasn't completed in the imports, so I just added a commit to fix this

@ajkyffin
Copy link
Copy Markdown
Member Author

ajkyffin commented Oct 9, 2025

Grrrr. Yes I broke it but I made the linter happy.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 17.42424% with 109 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.91%. Comparing base (bef86ae) to head (efb2f74).
⚠️ Report is 53 commits behind head on main.

Files with missing lines Patch % Lines
scigateway_auth/src/oidc.py 0.00% 57 Missing ⚠️
scigateway_auth/routers/authentication.py 0.00% 40 Missing ⚠️
scigateway_auth/src/authentication.py 27.27% 8 Missing ⚠️
scigateway_auth/common/config.py 82.60% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #154       +/-   ##
===========================================
- Coverage   65.55%   47.91%   -17.64%     
===========================================
  Files           9       12        +3     
  Lines         360      480      +120     
  Branches       13        0       -13     
===========================================
- Hits          236      230        -6     
- Misses        124      250      +126     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ajkyffin ajkyffin marked this pull request as ready for review November 24, 2025 16:05
Copy link
Copy Markdown
Contributor

@patrick-austin patrick-austin left a comment

Choose a reason for hiding this comment

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

Looks OK, the upload to codecov seems to be failing (but I don't have the permissions to dif to deeply so not sure?) but coverage is still 60% for me locally, and the new lines not covered are in a file that wasn't covered before either (routers/authentication.py).

There were a couple of places where we might be able use / benefit from SecretStr, but functionally this shouldn't change anything. Given it's last working day @ajkyffin I'm happy to approve this as is without bogging things down. Extending the use of SecretStr (if it's desirable) can be done as a follow up issue/PR.

from typing import List, Self

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, model_validator
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
from pydantic import BaseModel, ConfigDict, model_validator
from pydantic import BaseModel, ConfigDict, model_validator, SecretStr

To be used for secrets.

display_name: str
configuration_url: str
client_id: str
client_secret: str = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
client_secret: str = None
client_secret: SecretStr = None

SecretStr prevents secret values from appearing in logs, so might be useful here.

oidc_providers: dict[str, OidcProviderConfig] = {}
oidc_redirect_uri: str = None
oidc_icat_authenticator: str = None
oidc_icat_authenticator_token: str = None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
oidc_icat_authenticator_token: str = None
oidc_icat_authenticator_token: SecretStr = None

Would this also benefit from being a SecretStr?

Comment on lines +59 to +65
providers[provider_id] = {
"display_name": provider_config.display_name,
"configuration_url": provider_config.configuration_url,
"client_id": provider_config.client_id,
"pkce": False if provider_config.client_secret else True,
"scope": provider_config.scope,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could probably do this with a combination of exclude and serialization aliases, but if it works as is then that's fine too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nah

@ajkyffin ajkyffin merged commit ed7d888 into main Dec 9, 2025
10 checks passed
@ajkyffin ajkyffin deleted the oidc branch December 9, 2025 19:35
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.

Implement OIDC handler

3 participants