diaspora/lib/openid_connect/protected_resource_endpoint.rb
theworldbright 3cbe75469b Add support for scopes
Remove scopes from tokens

Squashed commits:

[83db38f] Add redirect uris to supported metadata
2016-01-04 16:49:51 +09:00

15 lines
572 B
Ruby

module OpenidConnect
module ProtectedResourceEndpoint
attr_reader :current_token
def require_access_token(*required_scopes)
@current_token = request.env[Rack::OAuth2::Server::Resource::ACCESS_TOKEN]
unless @current_token && @current_token.authorization
raise Rack::OAuth2::Server::Resource::Bearer::Unauthorized.new("Unauthorized user")
end
unless @current_token.authorization.try(:accessible?, required_scopes)
raise Rack::OAuth2::Server::Resource::Bearer::Forbidden.new(:insufficient_scope)
end
end
end
end