-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ class PreAuthorization | |
|
||
validate :client_id, error: :invalid_request | ||
validate :client, error: :invalid_client | ||
# The authorize_resource_owner_for_client config option is used for this validation | ||
validate :access_to_client, error: :invalid_client | ||
validate :redirect_uri, error: :invalid_redirect_uri | ||
validate :params, error: :invalid_request | ||
validate :response_type, error: :unsupported_response_type | ||
|
@@ -15,9 +17,9 @@ class PreAuthorization | |
validate :client_supports_grant_flow, error: :unauthorized_client | ||
|
||
attr_reader :server, :client_id, :client, :redirect_uri, :response_type, :state, | ||
:code_challenge, :code_challenge_method, :missing_param | ||
:code_challenge, :code_challenge_method, :missing_param, :resource_owner | ||
|
||
def initialize(server, attrs = {}) | ||
def initialize(server, attrs = {}, resource_owner = nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's OK for me just because |
||
@server = server | ||
@client_id = attrs[:client_id] | ||
@response_type = attrs[:response_type] | ||
|
@@ -26,6 +28,7 @@ def initialize(server, attrs = {}) | |
@state = attrs[:state] | ||
@code_challenge = attrs[:code_challenge] | ||
@code_challenge_method = attrs[:code_challenge_method] | ||
@resource_owner = resource_owner | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
end | ||
|
||
def authorizable? | ||
|
@@ -137,6 +140,10 @@ def pre_auth_hash | |
status: I18n.t("doorkeeper.pre_authorization.status"), | ||
} | ||
end | ||
|
||
def validate_access_to_client | ||
client.application.authorized_for_resource_owner?(@resource_owner) | ||
end | ||
end | ||
end | ||
end |
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.
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.