Class: V0::MapServicesController

Inherits:
SignIn::ServiceAccountApplicationController show all
Defined in:
app/controllers/v0/map_services_controller.rb

Constant Summary

Constants included from ExceptionHandling

ExceptionHandling::SKIP_SENTRY_EXCEPTION_TYPES

Constants included from SignIn::ServiceAccountAuthentication

SignIn::ServiceAccountAuthentication::BEARER_PATTERN

Constants included from SignIn::Authentication

SignIn::Authentication::BEARER_PATTERN

Instance Attribute Summary

Attributes inherited from SignIn::ServiceAccountApplicationController

#current_user

Instance Method Summary collapse

Methods included from Traceable

#set_trace_tags

Methods included from SentryControllerLogging

#set_tags_and_extra_context, #tags_context, #user_context

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods included from Headers

#set_app_info_headers

Methods included from ExceptionHandling

#render_errors, #report_mapped_exception, #report_original_exception, #skip_sentry_exception?, #skip_sentry_exception_types

Methods included from SignIn::ServiceAccountAuthentication

#authenticate_service_account, #authenticate_service_account_access_token, #bearer_token, #handle_authenticate_error, #validate_requested_scope

Methods included from SignIn::Authentication

#access_token, #access_token_authenticate, #authenticate, #authenticate_access_token, #bearer_token, #cookie_access_token, #handle_authenticate_error, #load_user, #load_user_object, #scrub_bearer_token, #validate_request_ip

Instance Method Details

#application_mismatch_errorObject (private)



31
32
33
34
35
36
# File 'app/controllers/v0/map_services_controller.rb', line 31

def application_mismatch_error
  {
    error: 'invalid_request',
    error_description: 'Application mismatch detected.'
  }
end

#missing_icn_errorObject (private)



38
39
40
41
42
43
# File 'app/controllers/v0/map_services_controller.rb', line 38

def missing_icn_error
  {
    error: 'invalid_request',
    error_description: 'Service account access token does not contain an ICN in `user_attributes` claim.'
  }
end

#sts_client_errorObject (private)



24
25
26
27
28
29
# File 'app/controllers/v0/map_services_controller.rb', line 24

def sts_client_error
  {
    error: 'server_error',
    error_description: 'STS failed to return a valid token.'
  }
end

#tokenObject

POST /v0/map_services/:application/token



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/v0/map_services_controller.rb', line 9

def token
  icn = @service_account_access_token.user_attributes['icn']
  result = MAP::SecurityToken::Service.new.token(application: params[:application].to_sym, icn:, cache: false)

  render json: result, status: :ok
rescue Common::Client::Errors::ClientError, Common::Exceptions::GatewayTimeout
  render json: sts_client_error, status: :bad_gateway
rescue MAP::SecurityToken::Errors::ApplicationMismatchError
  render json: application_mismatch_error, status: :bad_request
rescue MAP::SecurityToken::Errors::MissingICNError
  render json: missing_icn_error, status: :bad_request
end