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/user_basic_auth.rb

31 lines
817 B

require 'warden/basic_auth'
module OpenProject
module Authentication
module Strategies
module Warden
##
# Allows users to authenticate using their API key via basic auth.
# Note that in order for a user to be able to generate one
# `Setting.rest_api_enabled` has to be `1`.
#
# The basic auth credentials are expected to contain the literal 'apikey'
# as the user name and the API key as the password.
class UserBasicAuth < ::Warden::Strategies::BasicAuth
def self.user
'apikey'
end
def valid?
super && username == self.class.user
end
def authenticate_user(_, api_key)
User.find_by_api_key api_key
end
end
end
end
end
end