mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
Support for per-user API keys
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user