lib/rodauth/features/oauth.rb in rodauth-oauth-0.5.0 vs lib/rodauth/features/oauth.rb in rodauth-oauth-0.5.1
- old
+ new
@@ -137,11 +137,19 @@
auth_value_method :authorization_required_error_status, 401
auth_value_method :invalid_oauth_response_status, 400
auth_value_method :already_in_use_response_status, 409
# OAuth Applications
- auth_value_method :oauth_applications_path, "oauth-applications"
+ auth_value_method :oauth_applications_route, "oauth-applications"
+ def oauth_applications_path(opts = {})
+ route_path(oauth_applications_route, opts)
+ end
+
+ def oauth_applications_url(opts = {})
+ route_url(oauth_applications_route, opts)
+ end
+
auth_value_method :oauth_applications_table, :oauth_applications
auth_value_method :oauth_applications_id_column, :id
auth_value_method :oauth_applications_id_pattern, Integer
@@ -190,10 +198,11 @@
auth_value_method :is_authorization_server?, true
auth_value_method :oauth_unique_id_generation_retries, 3
auth_value_methods(
+ :oauth_application_path,
:fetch_access_token,
:oauth_unique_id_generator,
:secret_matches?,
:secret_hash,
:generate_token_hash,
@@ -361,13 +370,17 @@
end
end
end
end
+ def oauth_application_path(id)
+ "#{oauth_applications_path}/#{id}"
+ end
+
# /oauth-applications routes
def oauth_applications
- request.on(oauth_applications_path) do
+ request.on(oauth_applications_route) do
require_account
request.get "new" do
new_oauth_application_view
end
@@ -420,20 +433,24 @@
case request.path
when token_path, introspect_path
false
when revoke_path
!json_request?
- when authorize_path, %r{/#{oauth_applications_path}}
+ when authorize_path, oauth_applications_path
only_json? ? false : super
else
super
end
end
- # Overrides logged_in?, so that a valid authorization token also authnenticates a request
- def logged_in?
- super || authorization_token
+ # Overrides session_value, so that a valid authorization token also authenticates a request
+ def session_value
+ super || begin
+ return unless authorization_token
+
+ authorization_token[oauth_tokens_account_id_column]
+ end
end
def accepts_json?
return true if only_json?
@@ -1348,10 +1365,10 @@
{
issuer: issuer,
authorization_endpoint: authorize_url,
token_endpoint: token_url,
- registration_endpoint: route_url(oauth_applications_path),
+ registration_endpoint: oauth_applications_url,
scopes_supported: oauth_application_scopes,
response_types_supported: responses_supported,
response_modes_supported: response_modes_supported,
grant_types_supported: grant_types_supported,
token_endpoint_auth_methods_supported: %w[client_secret_basic client_secret_post],