FIX: client duplicate registration should be cleaned up

If for any reason we are unable to correct client id on a user api key
invalidate old keys for client/user
This commit is contained in:
Sam
2018-08-22 12:56:49 +10:00
parent 5d96809abd
commit 272de95175
2 changed files with 28 additions and 0 deletions

View File

@ -259,7 +259,15 @@ class Auth::DefaultCurrentUserProvider
end
api_key.update_columns(last_used_at: Time.zone.now)
if client_id.present? && client_id != api_key.client_id
# invalidate old dupe api key for client if needed
UserApiKey
.where(client_id: client_id, user_id: api_key.user_id)
.where('id <> ?', api_key.id)
.destroy_all
api_key.update_columns(client_id: client_id)
end