Skip to content

providers/oauth2: run invalidation flow for unauthenticated end-session requests - #23773

Merged
rissson merged 4 commits into
goauthentik:mainfrom
severin:fix/unauthenticated-invalidation-flow
Jul 28, 2026
Merged

rissson merged 4 commits into
goauthentik:mainfrom
severin:fix/unauthenticated-invalidation-flow

Conversation

@severin

@severin severin commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

Currently the Oauth2 end-session endpoint requires authentication. This PR changes it to make authentication optional: if no user is authenticated then the end-session endpoint still executes the associated invalidation flow and does a redirection to the post_logout_redirect_uri.

Code-wise this is implemented as follows:

A new flag on the policy view is introduced: require_authentication. If the flag is set to False then the view can be accessed even if no authenticated user is present.
The end-session view is changed to only do token revocation etc. if a authenticated user is present; if not it just executes the associated invalidation flow.

Why is this change needed?

Currently when the end-session endpoint is called with no authenticated user then the endpoint prompts the user to log in.

This is unexpected behaviour in my opinion: when I want to log out then I should be redirected to the post-logout URL and not asked to log in, even if I'm actually not logged in anymore.

Our specific use-case: We have a mobile app and log users in via an Authentik Oauth2 flow in a web view. The mobile app then gets access/refresh tokens and the user stays logged in via these tokens. When the app crashes or the OS reboots then the Authentik session is lost but the tokens are still valid; so we show the option to log out to the user. When a user then clicks "log out" we want to end their session (if it still exists) and have them redirected to a specific post-logout URL.

Note: The OIDC spec (https://openid.net/specs/openid-connect-rpinitiated-1_0.html#ValidationAndErrorHandling) is not 100% clear on this:

Note that because RP-Initiated Logout Requests are intended to be idempotent, it is explicitly not an error for an RP to request that a logout be performed when the OP does not consider that the End-User is logged in with the OP at the requesting RP

How was this tested?

Unit tests. Hitting the end-session endpoint on a local instance with a valid session and without.


Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)

Disclaimer

I used AI when working on this PR, but I reviewed all the changes before pushing. I didn't find any "no AI" policy in your contribution guidelines (in fact, there are AGENTS.md/CLAUDE.md files in the repo), so I assume AI use is no problem. If this is violating some rules though then please feel free to close this PR.

@severin
severin requested a review from a team as a code owner July 6, 2026 14:08
@rissson
rissson requested review from BeryJu and PeshekDotDev July 6, 2026 14:11
@netlify

netlify Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit ac7ac0c
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a56576ab9a6840008b47d54
😎 Deploy Preview https://deploy-preview-23773--authentik-storybook.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.

@netlify

netlify Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit ac7ac0c
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a56576a2f1ca40008583274
😎 Deploy Preview https://deploy-preview-23773--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.

@netlify

netlify Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit ac7ac0c
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a56576a958b2c0008ecf25d
😎 Deploy Preview https://deploy-preview-23773--authentik-integrations.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.

@codecov

codecov Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.26%. Comparing base (ba4d3ab) to head (ac7ac0c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23773      +/-   ##
==========================================
- Coverage   93.31%   93.26%   -0.05%     
==========================================
  Files        1045     1045              
  Lines       61401    61414      +13     
  Branches      424      424              
==========================================
- Hits        57296    57278      -18     
- Misses       4105     4136      +31     
Flag Coverage Δ
conformance 36.12% <60.71%> (-0.01%) ⬇️
e2e 41.28% <39.28%> (-0.02%) ⬇️
integration 32.05% <3.57%> (-0.50%) ⬇️
rust 0.00% <ø> (ø)
unit 92.41% <78.57%> (+<0.01%) ⬆️
unit-migrate 92.45% <78.57%> (+<0.01%) ⬆️

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

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

@BeryJu BeryJu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one implementation nit otherwise LGTM, i'll defer to @PeshekDotDev for the OIDC SLO side

Comment thread authentik/policies/views.py Resolved
@severin
severin requested a review from BeryJu July 13, 2026 07:50
@severin

severin commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@BeryJu @PeshekDotDev could you have a look at this again?

@BeryJu BeryJu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM implementation wise

@therour

therour commented Jul 14, 2026

Copy link
Copy Markdown

@BeryJu may I know when this is planned to be released? currently this features blocks me to replace auth0 with authentik. our RP-app currently does refresh token in the backend so the RP session is longer and extendable than the authentik session

@PeshekDotDev

Copy link
Copy Markdown
Contributor

Hey @severin , did you run into this issue on a release build of authentik, or when running it locally?

@PeshekDotDev

PeshekDotDev commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

There was an accidental regression with single logout that was fixed in this pr #23919 . After adding that, I don't think this PR works as intended. Let me test some things

@PeshekDotDev

Copy link
Copy Markdown
Contributor

Apologies, all is good with this pr

@severin

severin commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking @PeshekDotDev.

How does merging PRs work? Do you do that when you see fit?

@rissson
rissson merged commit 7c0ad2d into goauthentik:main Jul 28, 2026
116 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.

5 participants