From 64da4c5368c3ae729fe12f4c389647994ae26b29 Mon Sep 17 00:00:00 2001 From: Andrej Date: Tue, 28 Feb 2023 16:42:56 +0100 Subject: [PATCH] Fix connected device model for request without device id [SCI-7972] --- app/models/connected_device.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/connected_device.rb b/app/models/connected_device.rb index 2557682c6..40771bc4a 100644 --- a/app/models/connected_device.rb +++ b/app/models/connected_device.rb @@ -2,6 +2,7 @@ class ConnectedDevice < ApplicationRecord belongs_to :oauth_access_token, class_name: 'Doorkeeper::AccessToken' + validates :uid, presence: true after_destroy :revoke_token @@ -10,8 +11,10 @@ class ConnectedDevice < ApplicationRecord end def self.from_request_headers(headers, token = nil) + return unless headers['Device-Id'] + current_token = Doorkeeper::AccessToken.find_by( - token: headers['Authorization'].gsub(/Bearer\s/, '') + token: headers['Authorization']&.gsub(/Bearer\s/, '') ) return unless token || current_token