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

Add option to authorize the calling user to access an Application #1354

Merged

Conversation

JoshNorthrup
Copy link
Contributor

Summary

I've added an option to define whether a user can authorize an application.
My specific use case is the following:

  • All users belong to an organization
  • Each Application belongs to an organization (via a foreign key on Application)
  • I don't want users to be able to authorize an application that belongs to a different organization or see that it even exists for privacy reasons.

This is now achievable with the new option:

application_access do |resource_owner, application|
  resource_owner.org_id == application.org_id
end

When this validation fails the invalid_client error is used so it's indistinguishable from a nonexistent Application

spec/lib/oauth/pre_authorization_spec.rb Outdated Show resolved Hide resolved
spec/lib/oauth/pre_authorization_spec.rb Outdated Show resolved Hide resolved
spec/controllers/authorizations_controller_spec.rb Outdated Show resolved Hide resolved
spec/controllers/authorizations_controller_spec.rb Outdated Show resolved Hide resolved
spec/controllers/authorizations_controller_spec.rb Outdated Show resolved Hide resolved
spec/controllers/authorizations_controller_spec.rb Outdated Show resolved Hide resolved
lib/doorkeeper/orm/active_record/mixins/application.rb Outdated Show resolved Hide resolved
lib/doorkeeper/config.rb Outdated Show resolved Hide resolved
app/controllers/doorkeeper/authorizations_controller.rb Outdated Show resolved Hide resolved
app/controllers/doorkeeper/authorizations_controller.rb Outdated Show resolved Hide resolved
@JoshNorthrup JoshNorthrup force-pushed the user-application-access-control branch from b34d790 to 93d0857 Compare January 29, 2020 17:16
spec/lib/oauth/pre_authorization_spec.rb Outdated Show resolved Hide resolved
spec/controllers/authorizations_controller_spec.rb Outdated Show resolved Hide resolved
spec/controllers/authorizations_controller_spec.rb Outdated Show resolved Hide resolved
spec/controllers/authorizations_controller_spec.rb Outdated Show resolved Hide resolved
spec/controllers/authorizations_controller_spec.rb Outdated Show resolved Hide resolved
@JoshNorthrup JoshNorthrup force-pushed the user-application-access-control branch 2 times, most recently from e8d1b0d to d120c92 Compare January 29, 2020 18:34
Copy link
Member

@nbulaj nbulaj left a comment

Choose a reason for hiding this comment

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

Sorry, have little time to watch the PR. Thanks for the proposal, we need to do some work and then we can merge <3

app/controllers/doorkeeper/authorizations_controller.rb Outdated Show resolved Hide resolved
lib/doorkeeper/config.rb Outdated Show resolved Hide resolved
lib/doorkeeper/oauth/pre_authorization.rb Outdated Show resolved Hide resolved
@JoshNorthrup JoshNorthrup force-pushed the user-application-access-control branch from d120c92 to dcd7c1b Compare February 6, 2020 14:39
@JoshNorthrup JoshNorthrup force-pushed the user-application-access-control branch from dcd7c1b to 65934c2 Compare February 6, 2020 14:41
Copy link
Member

@nbulaj nbulaj left a comment

Choose a reason for hiding this comment

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

Let's do some renaming and LGTM for me 🚝
Thanks for your work!

lib/doorkeeper/config.rb Outdated Show resolved Hide resolved
@@ -7,6 +7,7 @@ class PreAuthorization

validate :client_id, error: :invalid_request
validate :client, error: :invalid_client
validate :access_to_client, error: :invalid_client
Copy link
Member

@nbulaj nbulaj Feb 7, 2020

Choose a reason for hiding this comment

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

And considering comment about the option name let rename it to resource_owner_authorized_for_client. Don't get angst about the long naming just because I think it must be explicit rather than implicit.

@@ -17,7 +18,7 @@ class PreAuthorization
attr_reader :server, :client_id, :client, :redirect_uri, :response_type, :state,
:code_challenge, :code_challenge_method, :missing_param

def initialize(server, attrs = {})
def initialize(server, attrs = {}, resource_owner = nil)
Copy link
Member

Choose a reason for hiding this comment

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

It's OK for me just because attrs not options, so we can add one more argument

@@ -26,6 +27,7 @@ def initialize(server, attrs = {})
@state = attrs[:state]
@code_challenge = attrs[:code_challenge]
@code_challenge_method = attrs[:code_challenge_method]
@resource_owner = resource_owner
Copy link
Member

Choose a reason for hiding this comment

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

Let's add it also to attr_readers, maybe we wanna to access it in the future for some reason

lib/doorkeeper/orm/active_record/mixins/application.rb Outdated Show resolved Hide resolved
@JoshNorthrup JoshNorthrup force-pushed the user-application-access-control branch from 65934c2 to df87749 Compare February 7, 2020 14:57
Copy link
Member

@nbulaj nbulaj left a comment

Choose a reason for hiding this comment

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

Thanks!

@nbulaj nbulaj merged commit 6004459 into doorkeeper-gem:master Feb 9, 2020
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