Skip to content

sources/oauth: Fallback to id field when sub is missing in OIDC callback - #22672

Merged
BeryJu merged 4 commits into
goauthentik:mainfrom
v-kamerdinerov:fix/oidc-callback-fallback-id-to-sub
Jun 3, 2026
Merged

BeryJu merged 4 commits into
goauthentik:mainfrom
v-kamerdinerov:fix/oidc-callback-fallback-id-to-sub

Conversation

@v-kamerdinerov

@v-kamerdinerov v-kamerdinerov commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Fix: Fallback to id field when sub is missing in OIDC callback

Problem

Some OAuth2 providers that expose an OIDC-compatible endpoint do not return the standard sub claim in their profile response. Instead, they use a provider-specific id field.

Example is Yandex OAuth — its profile endpoint returns id rather than sub, which caused OpenIDConnectOAuth2Callback.get_user_id() to always return None and authentication to fail with:

Authentication Failure: Could not determine id.

Also can help with issue - #16115

Solution

Updated get_user_id in OpenIDConnectOAuth2Callback to fall back to the id field when sub is not present:

def get_user_id(self, info: dict[str, str]) -> str | None:
    return str(info.get("sub") or info.get("id"))

This keeps full compatibility with standard OIDC providers that return sub, while also supporting non-standard providers like Yandex that use id.

Affected providers

  • Yandex OAuth — returns id instead of sub
  • Any other OAuth2/OIDC provider that uses id as the unique user identifier

Step for reproducing

Verified against Yandex OAuth source — authentication now completes successfully and the correct user identifier is extracted from the profile response.

Signed-off-by: Vlad Kamerdinerov <[email protected]>
@v-kamerdinerov
v-kamerdinerov requested a review from a team as a code owner May 26, 2026 17:01
@netlify

netlify Bot commented May 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit cf5cba4
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a1ffe2f5376d70007845d2e
😎 Deploy Preview https://deploy-preview-22672--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@BeryJu BeryJu changed the title Fix: Fallback to id field when sub is missing in OIDC callback sources/oauth: Fallback to id field when sub is missing in OIDC callback Jun 3, 2026
@codecov

codecov Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.25%. Comparing base (4a267b3) to head (cf5cba4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #22672      +/-   ##
==========================================
- Coverage   93.29%   93.25%   -0.05%     
==========================================
  Files        1033     1033              
  Lines       60150    60150              
  Branches      400      400              
==========================================
- Hits        56116    56091      -25     
- Misses       4034     4059      +25     
Flag Coverage Δ
conformance 36.56% <0.00%> (+<0.01%) ⬆️
e2e 41.81% <100.00%> (+<0.01%) ⬆️
integration 32.51% <0.00%> (-0.49%) ⬇️
rust 0.00% <ø> (ø)
unit 92.23% <100.00%> (+<0.01%) ⬆️
unit-migrate 92.26% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@BeryJu
BeryJu force-pushed the fix/oidc-callback-fallback-id-to-sub branch from dc00d35 to cf5cba4 Compare June 3, 2026 10:13
@BeryJu
BeryJu merged commit 5681aba into goauthentik:main Jun 3, 2026
156 of 160 checks passed
dominic-r pushed a commit that referenced this pull request Jun 4, 2026
…allback (#22672)

fix/oidc-callback-fallback-id-to-sub

Signed-off-by: Vlad Kamerdinerov <[email protected]>
Co-authored-by: Jens Langhammer <[email protected]>
kensternberg-authentik added a commit that referenced this pull request Jun 30, 2026
* main: (175 commits)
  web: fix British spellings flagged by cspell (#22820)
  web: Flesh out frontend, E2E, agent instructions. (#22388)
  root: update gen-changelog to filter unnecessary commits (#22550)
  root: gitignore release generation artifacts (#22549)
  sources/oauth: Fallback to `id` field when `sub` is missing in OIDC callback (#22672)
  translate: Updates for project authentik and language fr_FR (#22687)
  ci: replace deprecated app-id with client-id for actions/create-github-app-token (#22799)
  web: bump @playwright/test from 1.59.1 to 1.60.0 in /web (#22476)
  web: bump the storybook group across 1 directory with 5 updates (#22653)
  website/docs: add oidc issuer information (#22556)
  ci: bump snok/container-retention-policy from 3.0.1 to 3.1.0 (#22778)
  website: bump the build group across 1 directory with 9 updates (#22669)
  web: bump knip from 6.12.0 to 6.14.1 in /web (#22657)
  ci: update ubuntu version of ARM runners (#22798)
  core: bump openapitools/openapi-generator-cli from v7.20.0 to v7.22.0 in /packages/client-go (#22573)
  core: bump axllent/mailpit from v1.30.0 to v1.30.1 in /tests/e2e (#22747)
  core: bump goauthentik/fips-python from `33d1ed9` to `7a06339` in /lifecycle/container (#22676)
  ci: explicitly exit Node lint scripts to fix CI hang (#22794)
  core: bump openapitools/openapi-generator-cli from v7.21.0 to v7.22.0 in /packages/client-ts (#22575)
  core: bump django-stubs[compatible-mypy] from 6.0.4 to 6.0.5 (#22748)
  ...
@mrekin

mrekin commented Jul 30, 2026

Copy link
Copy Markdown

Hi!
May be stupid question - when this fix will be included in any release?

@v-kamerdinerov

Copy link
Copy Markdown
Contributor Author

Hi! May be stupid question - when this fix will be included in any release?

Fixed at 2026.8.0!

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.

3 participants