module CowAuth::TokenAuth::AuthenticateRequest
Constants
- AUTHORIZATION_DELIMITERS
- AUTHORIZATION_REGEX
- SID_KEY
- TOKEN_KEY
Private Instance Methods
authenticate_user()
click to toggle source
# File lib/cow_auth/token_auth/authenticate_request.rb, line 15 def authenticate_user sid, auth_token = extract_credentials(request.authorization) if sid.present? && auth_token.present? user = authentication_class.find_by(sid: sid) @current_user = user.try(:authenticate_with_token, auth_token) ? user : nil return true if @current_user.present? end raise CowAuth::NotAuthenticatedError.new('User not authenticated.') end
current_user()
click to toggle source
# File lib/cow_auth/token_auth/authenticate_request.rb, line 33 def current_user return @current_user end
extract_credentials(authorization_header)
click to toggle source
# File lib/cow_auth/token_auth/authenticate_request.rb, line 25 def extract_credentials(authorization_header) return nil if authorization_header.blank? || !(authorization_header =~ /\A#{AUTHORIZATION_REGEX}/) params = authorization_header.sub(AUTHORIZATION_REGEX, '').split(/\s*#{AUTHORIZATION_DELIMITERS}\s*/) sid = params[1].sub(SID_KEY, '') if params[1] =~ /\A#{SID_KEY}/ auth_token = params[0].sub(TOKEN_KEY, '') if params[0] =~ /\A#{TOKEN_KEY}/ return sid, auth_token end