Module: AppRail::Airtable::AuthenticationHelpers

Defined in:
lib/app_rail/airtable/authentication_helpers.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



29
30
31
# File 'lib/app_rail/airtable/authentication_helpers.rb', line 29

def authenticate!
  halt 401 unless current_user
end

#authorization_headerObject



21
22
23
# File 'lib/app_rail/airtable/authentication_helpers.rb', line 21

def authorization_header
  request.env['HTTP_AUTHORIZATION']
end

#bearer_tokenObject



14
15
16
17
18
19
# File 'lib/app_rail/airtable/authentication_helpers.rb', line 14

def bearer_token
  authorization_values = authorization_header.split(' ')
  return nil unless authorization_values.count > 1

  authorization_values[1]
end

#current_userObject



6
7
8
# File 'lib/app_rail/airtable/authentication_helpers.rb', line 6

def current_user
  @current_user ||= find_current_user
end

#find_current_userObject



10
11
12
# File 'lib/app_rail/airtable/authentication_helpers.rb', line 10

def find_current_user
  authorization_header && bearer_token ? find_authenticatable_resource(access_token: bearer_token) : nil
end

#oauth_client_idObject



25
26
27
# File 'lib/app_rail/airtable/authentication_helpers.rb', line 25

def oauth_client_id
  ENV.fetch('OAUTH_CLIENT_ID')
end