Class: IBMCloudSdkCore::BearerTokenAuthenticator
- Inherits:
-
Authenticator
- Object
- Authenticator
- IBMCloudSdkCore::BearerTokenAuthenticator
- Defined in:
- lib/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.rb
Overview
Basic Authenticator
Constant Summary
Constants inherited from Authenticator
Authenticator::AUTH_TYPE_BASIC, Authenticator::AUTH_TYPE_BEARER_TOKEN, Authenticator::AUTH_TYPE_CP4D, Authenticator::AUTH_TYPE_IAM, Authenticator::AUTH_TYPE_NO_AUTH
Instance Attribute Summary collapse
-
#authentication_type ⇒ Object
Returns the value of attribute authentication_type.
Instance Method Summary collapse
-
#authenticate(headers) ⇒ Object
Adds the Authorization header, if possible.
-
#initialize(vars) ⇒ BearerTokenAuthenticator
constructor
A new instance of BearerTokenAuthenticator.
-
#validate ⇒ Object
Checks if all the inputs needed are present.
Constructor Details
#initialize(vars) ⇒ BearerTokenAuthenticator
Returns a new instance of BearerTokenAuthenticator.
11 12 13 14 15 16 17 18 19 |
# File 'lib/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.rb', line 11 def initialize(vars) defaults = { bearer_token: nil } vars = defaults.merge(vars) @bearer_token = vars[:bearer_token] @authentication_type = AUTH_TYPE_BEARER_TOKEN validate end |
Instance Attribute Details
#authentication_type ⇒ Object
Returns the value of attribute authentication_type.
10 11 12 |
# File 'lib/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.rb', line 10 def authentication_type @authentication_type end |
Instance Method Details
#authenticate(headers) ⇒ Object
Adds the Authorization header, if possible
22 23 24 |
# File 'lib/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.rb', line 22 def authenticate(headers) headers["Authorization"] = "Bearer #{@bearer_token}" end |
#validate ⇒ Object
Checks if all the inputs needed are present
27 28 29 |
# File 'lib/ibm_cloud_sdk_core/authenticators/bearer_token_authenticator.rb', line 27 def validate raise ArgumentError.new("The bearer token shouldn\'t be None.") if @bearer_token.nil? end |