Module: Authify::API::Helpers::APIUser
- Defined in:
- lib/authify/api/helpers/api_user.rb
Overview
Helper methods for API users
Instance Method Summary collapse
-
#auth ⇒ Object
This shouldn’t work via API calls.
- #current_user ⇒ Object
- #processed_headers ⇒ Object
- #remote_app ⇒ Object
- #update_current_user(user) ⇒ Object
Instance Method Details
#auth ⇒ Object
This shouldn’t work via API calls
39 40 41 |
# File 'lib/authify/api/helpers/api_user.rb', line 39 def auth {} end |
#current_user ⇒ Object
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_headers ⇒ Object
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_app ⇒ Object
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 |