Smooth out the finder API
This commit is contained in:
committed by
Stanko K.R.
parent
0ba43de61a
commit
caa4cd491e
@@ -59,8 +59,8 @@ module Authentication
|
|||||||
authorization_scheme, bearer_token = request.authorization.to_s.split(" ", 2)
|
authorization_scheme, bearer_token = request.authorization.to_s.split(" ", 2)
|
||||||
|
|
||||||
if authorization_scheme == "Bearer" && bearer_token.present?
|
if authorization_scheme == "Bearer" && bearer_token.present?
|
||||||
if access_token = Identity::AccessToken.find_by(token: bearer_token)
|
if identity = Identity.find_by_access_token(bearer_token)
|
||||||
Current.identity = access_token.identity
|
Current.identity = identity
|
||||||
else
|
else
|
||||||
head :unauthorized
|
head :unauthorized
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ class Identity < ApplicationRecord
|
|||||||
validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }
|
validates :email_address, format: { with: URI::MailTo::EMAIL_REGEXP }
|
||||||
normalizes :email_address, with: ->(value) { value.strip.downcase.presence }
|
normalizes :email_address, with: ->(value) { value.strip.downcase.presence }
|
||||||
|
|
||||||
|
def self.find_by_access_token(token)
|
||||||
|
AccessToken.find_by(token: token)&.identity
|
||||||
|
end
|
||||||
|
|
||||||
def send_magic_link(**attributes)
|
def send_magic_link(**attributes)
|
||||||
attributes[:purpose] = attributes.delete(:for) if attributes.key?(:for)
|
attributes[:purpose] = attributes.delete(:for) if attributes.key?(:for)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user