6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/lib/client_credentials_strategy.rb', line 6
def authenticate!
token = ::Doorkeeper::OAuth::Token.authenticate(request, :from_bearer_authorization)
fail! and throw(:warden, status: :unauthorized) unless token&.accessible?
scopes = case request.env.dig("action_dispatch.request.parameters", "action") || request.env.dig("action_dispatch.route_uri_pattern")
when "index", "show"
["public", "read"]
when "create", "update"
["write"]
when "destroy"
["delete"]
when "/upload"
["upload"]
end
fail! and throw(:warden, status: :forbidden) unless token.acceptable?(scopes)
resource_owner = if token.scopes == ["public"]
nil
else
token.application&.owner
end
if resource_owner&.active_for_authentication?
request.session_options[:skip] = true
success! resource_owner
end
end
|