OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/lib/open_project/authentication/strategies/warden/doorkeeper_oauth.rb

34 lines
893 B

require 'doorkeeper/grape/authorization_decorator'
module OpenProject
module Authentication
module Strategies
module Warden
##
# Allows testing authentication via doorkeeper OAuth2 token
#
class DoorkeeperOAuth < ::Warden::Strategies::Base
def valid?
@token = ::Doorkeeper::OAuth::Token.authenticate(decorated_request, *Doorkeeper.configuration.access_token_methods)
@token&.accessible? && @token.acceptable?(scope)
end
def authenticate!
user = User.where(id: @token.resource_owner_id).first
if user
success!(user)
else
fail!("No such user")
end
end
def decorated_request
::Doorkeeper::Grape::AuthorizationDecorator.new(request)
end
end
end
end
end
end