-
-
Notifications
You must be signed in to change notification settings - Fork 797
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
Implement OIDC RP-Initiated Logout #1244
Implement OIDC RP-Initiated Logout #1244
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1244 +/- ##
==========================================
+ Coverage 96.97% 97.24% +0.26%
==========================================
Files 31 31
Lines 1821 1994 +173
==========================================
+ Hits 1766 1939 +173
Misses 55 55
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There is one thing causing the tests to fail:
|
This PR should now be ready for a review. If I can do anything to make the review easier for you (e.g. deploy a demo app with the code, etc.), I'd be happy to help. |
@Qup42 simply run |
Yes I have fixed them locally. I just wanted to state why the builds fail, as the lint errors are in locations that didn't change with this PR. So I was hesitant to add them to this PR and didn't push the changes yet. |
@Qup42 Thank you so much for submitting this PR. I can't test it today, but I'll review first thing next week. I did do a quick scan over the code and the general gist looks good. A few thoughts came to mind
|
and
|
|
@Qup42 I've shared a gist of an end session endpoint I implemented for a project. I didn't implement the user confirmation part of the workflow, but I do have a sample of expired token validation you can grab and maybe a few other things... https://gist.github.com/dopry/36e8cb676b08697ad26612521993b57d |
246d2e9
to
a1407b7
Compare
@Qup42 FYI I've just rebased this |
Looking at your gist I see that you delete the access tokens. Previously libraries built on top of django-oauth-toolkit would do the actual logout. Now that we actually also logout a user this has to be considered. I'll integrate the token handling and token deletion from your gist in about three weeks once I'm done with my exams. |
|
Regarding expired tokens: have you tested that the code in your snipped does actually accept expired tokens? (Shouldn't Anyways ... if the code already accepts expired tokens - great. Otherwise |
Thanks for the QC on the JWT check,,, you're right... I looked back at the blame and check_claims=False and key=key got lost in a mismerge in another feature branch... sigh... makes me wish I had written the tests when I wrote the code. I think deleting tokens would probably be good. I used Oauth2AccessToken.objects.filter(user=request.user).delete(). I'd want to check that request wouldn't be too greedy and delete things like client credentials created by a user that should be persistent. I don't have an m2m or client credentials in my environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, Overloading _load_id_token with both validation and token loading caught my attention at first. Applying the single resposibility prinicpal here would lead us to decompose validating the provided token and loading a token into to two separate functions. It is paralell to the oauth2_validators._load_id_token
, so there is a an argument for maintaining consistency, so I would approve this.
@Qup42 any plans on implementing token removal along side logout?
Thanks for having a look. I also wasn't quite satisfied with that function. I have now split it into two: loading the IDToken and validating the claims. The difference to the validator is that the validation doesn't happen on the No worries - I haven't forgotten the token removal ;) I will probably implement it in the next couple days. |
It can now be configured whether tokens should be deleted at all and for which types of clients (public/confidential) and authorization grant types. Deleting tokens just because a User logs seems to be a bit against the idea of the tokens to me, especially for IDTokens. Currently I also delete the IDTokens of the user that is being logged out. I'm unsure about that aspect. Do you have any input on whether the IDTokens should also be deleted or kept? @dopry |
@Qup42 thanks for your work on this. I'm really looking forward to getting it in. I think a lot of people can benefit from this work.
I'm not working from the concept of a token and how they're intended to be used, but from the Users objective of being logged out. If a user has requested to be logged out of a specific RP or at the IDP, I suspect their expectation is that their session is ended and that their 'live' PII is fully invalidated and wiped. When I log out of a server side session based app, my session is fully deleted along with any identification info contained there in. It may still live at rest in the DB, but the sessions and live copy of the PII is gone. From a more practical perspective, I've seen a number of RP implementations use an IDToken as an auth token. Not saying it's right or should be actively supported, but I've seen it and we should consider it. Not all RPs will validate an ID Token on every request or before expiration anyway. They would re-request it on expiration at which point they probably couldn't get it without a valid auth token or auth session. RPs could also just continue to used the 'invalidated' token. Nothing is stopping then, I feel like it's best to tell RPs that the ID token is no longer valid of they try to check one once a use has actively ended their session. This is just my opinion. I could be overlooking cases like offline RP access to user data etc that aren't a typical part of the workflows I use. Since we have opposing views, I think we should try to lean back on spec to determine how to handle this scenario. Based on your reading of OAUTH related specs and tokens, why do you feel that ID Tokens shouldn't be deleted? |
We probably need to copy everything from jazzband/django-oauth-toolkit#1244 until it's merged
We probably need to copy everything from jazzband/django-oauth-toolkit#1244 until it's merged
@Qup42 I wanted to check in. I've been busy the last few weeks. I think it's okay to delete the tokens. In what cases would you not want to delete them? |
@dopry Hmm I guess you're right. Doing what most users expect is probably the better approach here. The deletion of the tokens can also be turned of should that be required. I also merged the master branch once more. What would be the next step going forward? |
Everything looks good from a code review perspective. I just wanted to be sure you felt it was complete before I dove into testing. I'll try to get to it today. |
cb395dc
to
bff4d25
Compare
@Qup42 I'm starting into testing today. I rebased your PR so the feature history will be linear. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a small thing. I'll get it if all goes well in further testing.
@dopry I'll wait for you to finish reviewing and integrate the changes after that in bulk. |
@dopry This might help with testing: https://github.com/n2ygk/dot-tutorial/blob/main/certification/notes.md The heroku app is not currently set up but I can do that. |
I was setting up an example IDP (django + django_oauth_toolkit) and RP (https://github.com/dopry/svelte-oidc) locally per #1266 to facilitate testing. My svelte-oidc project needed some love and I thought I'd kill two bird with one stone. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi.
First of all, I'm really glad to that you worked on this feature for DOT.
It was clearly not a small task, and I'm sure it will help a lot of people (including me !)
I've done some testing and I think there's a issue regarding logout without prompt sent from the RP server, so I added some comments in your pull request.
for more information, see https://pre-commit.ci
bff4d25
to
ba4d765
Compare
@Qup42 I've completed my review and it's working splendidly. The last changes are
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l love the solution by using a strict setting. There is one typo in the docs, If you can get around to fixing it that would be awesome. I gotta run to a meeting, if you haven't gotten to it before I'm back I'll update it when I do a final testing pass.
0fe3779
to
8413052
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@Qup42 Thank you so much for all your work on this. It is very appreciated. |
Fixes #1131
Description of the Change
Implement OIDC RP-Initiated Logout.
Regarding functionality the code is mostly finished. I am not yet satisfied with the structure of some parts of the code and would appreciate feedback or ideas to improve these points. Most functionality that
django-oauth-toolkit
provides is backed byoauthlib
. This is not the case with the RP-Initiated Logout and I think that most of my uncertainty comes from that.django-oauth-toolkit
are just passed on fromoauthlib
. The exceptions that are passend on don't require new exception classes.validate_logout_request
. For RP-Initiated Logout the actual core logic has to be implement indjango-oauth-toolkit
. Most other functionality can be forwarded tooauthlib
via already existing classes (OAuthLibCore
, etc.). But maybe there is a better place for this function.Checklist
CHANGELOG.md
updated (only for user relevant changes)AUTHORS
validate_logout_request
views/oidc.py