pull/30329/merge
Emelia Smith 2025-01-08 17:05:13 +00:00 committed by GitHub
commit 3bfe80647a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 6 deletions

View File

@ -16,14 +16,19 @@ class Api::V1::AppsController < Api::BaseController
redirect_uri: app_params[:redirect_uris],
scopes: app_scopes_or_default,
website: app_params[:website],
confidential: app_confidential?,
}
end
def app_confidential?
!app_params[:token_endpoint_auth_method] || app_params[:token_endpoint_auth_method] != 'none'
end
def app_scopes_or_default
app_params[:scopes] || Doorkeeper.configuration.default_scopes
end
def app_params
params.permit(:client_name, :scopes, :website, :redirect_uris, redirect_uris: [])
params.permit(:client_name, :scopes, :website, :token_endpoint_auth_method, :redirect_uris, redirect_uris: [])
end
end

View File

@ -8,7 +8,7 @@ class REST::CredentialApplicationSerializer < REST::ApplicationSerializer
end
def client_secret
object.secret
object.secret if object.confidential?
end
# Added for future forwards compatibility when we may decide to expire OAuth

View File

@ -31,10 +31,19 @@ Doorkeeper.configure do
# If you want to disable expiration, set this to nil.
access_token_expires_in nil
# Assign a custom TTL for implicit grants.
# custom_access_token_expires_in do |oauth_client|
# oauth_client.application.additional_settings.implicit_oauth_expiration
# end
# context.grant_type to compare with Doorkeeper::OAUTH grant type constants
# context.client for client (Doorkeeper::Application)
# context.scopes for scopes
custom_access_token_expires_in do |context|
# If the client is confidential (all clients pre 4.3), then we don't want to
# expire access tokens. Applications created by users are also considered
# confidential.
if context.client.confidential?
nil
else
15.minutes.to_i
end
end
# Use a custom class for generating the access token.
# https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
@ -167,6 +176,16 @@ Doorkeeper.configure do
grant_flows %w(authorization_code client_credentials)
# If the client is not a confidential client, it should not be able to use the
# client_credentials grant flow, since it cannot keep a secret.
allow_grant_flow_for_client do |grant_flow, client|
if grant_flow == Doorkeeper::OAuth::CLIENT_CREDENTIALS
client.confidential?
else
true
end
end
# Under some circumstances you might want to have applications auto-approved,
# so that the user skips the authorization step.
# For example if dealing with a trusted application.