Class: AdminApiController

Inherits:
ApplicationController show all
Defined in:
lib/nexmo_developer/app/controllers/admin_api_controller.rb

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::CONFIG

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin!, #not_found, #redirect_vonage_domain

Methods included from ApplicationHelper

#active_sidenav_item, #canonical_base, #canonical_base_from_config, #canonical_path, #canonical_url, #dashboard_cookie, #search_enabled?, #set_utm_cookie, #theme

Instance Method Details

#authenticateObject



11
12
13
14
15
16
# File 'lib/nexmo_developer/app/controllers/admin_api_controller.rb', line 11

def authenticate
  return true if authenticated?

  render plain: 'Unauthorized', status: :unauthorized
  false
end

#authenticated?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
# File 'lib/nexmo_developer/app/controllers/admin_api_controller.rb', line 4

def authenticated?
  bearer_token = request.headers['Authorization']&.match(/^Bearer /)&.post_match
  return false unless bearer_token

  User.exists?(admin: true, nexmo_developer_api_secret: bearer_token)
end