Skip to content
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

Update changes for Doorkeeper 5.2 #97

Conversation

linhdangduy
Copy link
Contributor

@linhdangduy linhdangduy commented Nov 17, 2019

#85 tried to make doorkeeper-openid_connect to be compatible with doorkeeper 5.2, but there are errors to be fixed and some place to refactor. So I create this PR to "completely" make this gem compatible with doorkeeper 5.2.

What PR does

The work is explained as PR's comment below 👇

@linhdangduy linhdangduy force-pushed the refactoring_based_on_doorkeeper_5.2 branch from 1fe2fc1 to 83f8c44 Compare November 17, 2019 08:47
Copy link
Contributor Author

@linhdangduy linhdangduy left a comment

Choose a reason for hiding this comment

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

These comments are for explaining the changes in PR.
(5 commits, each commit in this pull is for each change)

lib/doorkeeper/oauth/id_token_request.rb Show resolved Hide resolved
pre_auth.client,
owner.id,
pre_auth.scopes
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change this to be the same implement with doorkeeper:
https://github.com/doorkeeper-gem/doorkeeper/blob/v5.2.0/app/controllers/doorkeeper/authorizations_controller.rb#L44-L50

If don't have any access_token, it will return nil

Copy link
Member

Choose a reason for hiding this comment

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

Hmm this is related to a subtle bug which I'm not sure has been fixed in Doorkeeper: doorkeeper-gem/doorkeeper#1197

The spec mentioned in the issue is still there in master / v5.2.2: https://github.com/doorkeeper-gem/doorkeeper/blob/v5.2.2/spec/models/doorkeeper/access_token_spec.rb#L544-L548

Do you know anything about this? I'm not sure if this is still relevant, I'll see if we have a spec for this case or add one in master if necessary.

Copy link
Member

@toupeira toupeira Dec 2, 2019

Choose a reason for hiding this comment

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

@linhdangduy ok I had a look, we don't have a spec for this and I decided not to add one, because it wouldn't make much sense to use a different logic here if Doorkeeper would then end up using the other logic later anyway.

So basically, let's ignore this edge-case and revisit if it actually causes problems for someone 😉

I also saw authorizations_controller.rb defines matching_token? with the same code, so can we replace oidc_consent_required? below with simply:

!skip_authorization && !matching_token?

And it looks like matching_token? in Doorkeeper should actually do a .present? check at the end? Currently it can return an empty array, which would be truthy even if no matching token is actually found.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@toupeira

so can we replace oidc_consent_required? below with simply:
!skip_authorization && !matching_token?

yeah, we can simply use existed matching_token?.
I think about it before, misunderstood that there will be a loop because matching_token? use current_resource_owner, but what doorkeeper-oidc monkey-patched is authenticate_resource_owner!, not current_resource_owner.
So incase we use it, we doesn't need to pass owner to matching_tokens_for_oidc_resource_owner method.

And it looks like matching_token? in Doorkeeper should actually do a .present? check at the end? Currently it can return an empty array, which would be truthy even if no matching token is actually found.

The matching_token? method return nil if matching record was not found, not an empty array, I think. We can see the comment here.

@linhdangduy linhdangduy force-pushed the refactoring_based_on_doorkeeper_5.2 branch from 83f8c44 to 867ed7c Compare November 18, 2019 03:03
Copy link
Member

@toupeira toupeira left a comment

Choose a reason for hiding this comment

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

@linhdangduy thank you very much for this PR, and please excuse the delay!

This generally LGTM, just some minor notes. I'll get back to you soon after I tested that edge-case about reauthenticating with fewer scopes.

pre_auth.client,
owner.id,
pre_auth.scopes
)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm this is related to a subtle bug which I'm not sure has been fixed in Doorkeeper: doorkeeper-gem/doorkeeper#1197

The spec mentioned in the issue is still there in master / v5.2.2: https://github.com/doorkeeper-gem/doorkeeper/blob/v5.2.2/spec/models/doorkeeper/access_token_spec.rb#L544-L548

Do you know anything about this? I'm not sure if this is still relevant, I'll see if we have a spec for this case or add one in master if necessary.

spec/lib/oauth/pre_authorization_spec.rb Show resolved Hide resolved
@camilo0365
Copy link

@toupeira @linhdangduy Do you reckon I can help you move forward this much wanted fix? 😄

@linhdangduy
Copy link
Contributor Author

linhdangduy commented Jan 17, 2020

Definitely, this has to be merged and released ASAP.

I'm putting my eyes on this pull request, too. If it still has problems, just feedback, i will fix it.

@nbulaj
Copy link
Member

nbulaj commented Feb 5, 2020

@toupeira can we merge this? I took a look and it LGTM 🚢 Or let me know if I can help with it somehow

@toupeira
Copy link
Member

toupeira commented Feb 7, 2020

@linhdangduy @nbulaj really sorry for dropping the ball on this again 🙈 Will merge now and release a new version soon after going through the other open PRs and issues.

@toupeira toupeira merged commit 7f0022e into doorkeeper-gem:master Feb 7, 2020
@nbulaj
Copy link
Member

nbulaj commented Feb 7, 2020

Thanks @toupeira ! Also just as side note - you can ping me anytime if you need some help with Doorkeeper internals or found some strange or breaking changes in it. I'll try to help you with them.

Also I reviewed some Doorkeeper extensions (like this one and doorkeeper-jwt) and found that Doorkeeper has some high-coupling in few classes, so I've done some refactoring to allow code reuse for extensions. Like https://github.com/doorkeeper-gem/doorkeeper/pull/1359/files and doorkeeper-gem/doorkeeper@78c822b#diff-30d1c02eb523d3fdbe0ea87cd811bc3fR25

You could re-use Option DSL and mapper now, but it would be available only from Doorkeeper 5.4 :)

@toupeira
Copy link
Member

toupeira commented Feb 7, 2020

@nbulaj thanks, that looks great and I appreciate your help! 👍

I've added a note to the README now that we're looking for maintainers, I don't feel too great about how I keep neglecting it 🤦‍♂️

If you want I can add you as a gem owner so you can cut releases as well, my only requirement would be that you enable 2FA on rubygems.org 😉

@nbulaj
Copy link
Member

nbulaj commented Feb 7, 2020

Yep, it's a great idea @toupeira. I have 2FA both on GitHub and rubygems :)

@toupeira
Copy link
Member

toupeira commented Feb 7, 2020

@nbulaj perfect, you're added now! 👍 The release process is documented at https://github.com/doorkeeper-gem/doorkeeper-openid_connect/blob/master/CONTRIBUTING.md#release-process

@linhdangduy linhdangduy deleted the refactoring_based_on_doorkeeper_5.2 branch February 7, 2020 23:57
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.

Nonces are not stored
4 participants