Class: Worldline::Acquiring::SDK::Authentication::OAuth2Authenticator
- Inherits:
-
Authenticator
- Object
- Authenticator
- Worldline::Acquiring::SDK::Authentication::OAuth2Authenticator
- Defined in:
- lib/worldline/acquiring/sdk/authentication/oauth2_authenticator.rb
Overview
Authenticates requests made to the Worldline Acquiring platform using OAuth2.
Defined Under Namespace
Classes: AccessToken, TokenType
Instance Method Summary collapse
- #get_authorization(http_method, resource_uri, request_headers) ⇒ Object
-
#initialize(communicator_configuration) ⇒ OAuth2Authenticator
constructor
Constructs a new OAuth2Authenticator instance using the provided CommunicatorConfiguration.
Constructor Details
#initialize(communicator_configuration) ⇒ OAuth2Authenticator
Constructs a new OAuth2Authenticator instance using the provided CommunicatorConfiguration.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/worldline/acquiring/sdk/authentication/oauth2_authenticator.rb', line 56 def initialize(communicator_configuration) raise ArgumentError unless communicator_configuration.oauth2_client_id and not communicator_configuration.oauth2_client_id.strip.empty? raise ArgumentError unless communicator_configuration.oauth2_client_secret and not communicator_configuration.oauth2_client_secret.strip.empty? raise ArgumentError unless communicator_configuration.oauth2_token_uri and not communicator_configuration.oauth2_token_uri.strip.empty? raise ArgumentError unless communicator_configuration.connect_timeout > 0 raise ArgumentError unless communicator_configuration.socket_timeout > 0 @access_tokens = Concurrent::Map.new @client_id = communicator_configuration.oauth2_client_id @client_secret = communicator_configuration.oauth2_client_secret @token_uri = communicator_configuration.oauth2_token_uri @connect_timeout = communicator_configuration.connect_timeout @socket_timeout = communicator_configuration.socket_timeout @proxy_configuration = communicator_configuration.proxy_configuration end |
Instance Method Details
#get_authorization(http_method, resource_uri, request_headers) ⇒ Object
75 76 77 78 79 |
# File 'lib/worldline/acquiring/sdk/authentication/oauth2_authenticator.rb', line 75 def (http_method, resource_uri, request_headers) token_type = get_token_type(resource_uri&.path) access_token = @access_tokens.compute(token_type.path) { |existing_token| get_valid_access_token(existing_token, token_type) } "Bearer #{access_token.token}" end |