Module: Authify::API::Helpers::APIUser

Defined in:
lib/authify/api/helpers/api_user.rb

Overview

Helper methods for API users

Instance Method Summary collapse

Instance Method Details

#authObject

This shouldn’t work via API calls



39
40
41
# File 'lib/authify/api/helpers/api_user.rb', line 39

def auth
  {}
end

#current_userObject



6
7
8
9
# File 'lib/authify/api/helpers/api_user.rb', line 6

def current_user
  email = env.key?(:user) ? env[:user]['username'] : nil
  @current_user ||= email ? Models::User.find_by_email(email) : nil
end

#processed_headersObject



32
33
34
35
36
# File 'lib/authify/api/helpers/api_user.rb', line 32

def processed_headers
  @headers ||= request.env.dup.each_with_object({}) do |(k, v), acc|
    acc[Regexp.last_match(1).downcase] = v if k =~ /^http_(.*)/i
  end
end

#remote_appObject



11
12
13
14
15
16
17
# File 'lib/authify/api/helpers/api_user.rb', line 11

def remote_app
  @remote_app ||= if processed_headers.key?('x_authify_access')
                    access = processed_headers['x_authify_access']
                    secret = processed_headers['x_authify_secret']
                    Models::TrustedDelegate.from_access_key(access, secret)
                  end
end

#update_current_user(user) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/authify/api/helpers/api_user.rb', line 19

def update_current_user(user)
  found_user = if user.is_a? Authify::API::Models::User
                 user
               elsif user.is_a? Integer
                 Models::User.find(user)
               elsif user.is_a? String
                 Models::User.find_by_email(user)
               end

  halt 422 unless found_user
  @current_user = found_user
end