Support for per-user API keys

This commit is contained in:
Robin Ward
2013-10-22 15:53:08 -04:00
parent 5e2d8dcf37
commit 348e2e3ef2
45 changed files with 670 additions and 87 deletions

View File

@ -38,12 +38,17 @@ class Auth::DefaultCurrentUserProvider
# possible we have an api call, impersonate
unless current_user
if api_key = request["api_key"]
if api_username = request["api_username"]
if SiteSetting.api_key_valid?(api_key)
@env[API_KEY] = true
if api_key_value = request["api_key"]
api_key = ApiKey.where(key: api_key_value).includes(:user).first
if api_key.present?
@env[API_KEY] = true
if api_key.user.present?
current_user = api_key.user
elsif api_username = request["api_username"]
current_user = User.where(username_lower: api_username.downcase).first
end
end
end
end