Class: ShellDataReportingApIs::OAuthAuthorizationController

Inherits:
BaseController
  • Object
show all
Defined in:
lib/shell_data_reporting_ap_is/controllers/o_auth_authorization_controller.rb

Overview

OAuthAuthorizationController

Constant Summary

Constants inherited from BaseController

BaseController::GLOBAL_ERRORS

Instance Attribute Summary

Attributes inherited from BaseController

#config, #http_call_back

Instance Method Summary collapse

Methods inherited from BaseController

#initialize, #new_api_call_builder, #new_parameter, #new_request_builder, #new_response_handler, user_agent

Constructor Details

This class inherits a constructor from ShellDataReportingApIs::BaseController

Instance Method Details

#request_token_bearer_token(authorization, scope: nil, _field_parameters: nil) ⇒ OAuthToken

Create a new OAuth 2 token. Basic auth format space-delimited list. supported by this endpoint.

Parameters:

  • authorization (String)

    Required parameter: Authorization header in

  • scope (String) (defaults to: nil)

    Optional parameter: Requested scopes as a

  • _field_parameters (Hash) (defaults to: nil)

    Additional optional form parameters are

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shell_data_reporting_ap_is/controllers/o_auth_authorization_controller.rb', line 17

def request_token_bearer_token(authorization,
                               scope: nil,
                               _field_parameters: nil)
  new_api_call_builder
    .request(new_request_builder(HttpMethodEnum::POST,
                                 '/v1/oauth/token',
                                 Server::OAUTH_SERVER)
               .form_param(new_parameter('client_credentials', key: 'grant_type'))
               .header_param(new_parameter(authorization, key: 'Authorization'))
               .form_param(new_parameter(scope, key: 'scope'))
               .header_param(new_parameter('application/x-www-form-urlencoded', key: 'content-type'))
               .header_param(new_parameter('application/json', key: 'accept'))
               .additional_form_params(_field_parameters))
    .response(new_response_handler
               .deserializer(APIHelper.method(:custom_type_deserializer))
               .deserialize_into(OAuthToken.method(:from_hash))
               .local_error('400',
                            'OAuth 2 provider returned an error.',
                            OAuthProviderException)
               .local_error('401',
                            'OAuth 2 provider says client authentication failed.',
                            OAuthProviderException))
    .execute
end