Class: MsRest::TokenCredentials
- Inherits:
-
ServiceClientCredentials
- Object
- ServiceClientCredentials
- MsRest::TokenCredentials
- Defined in:
- lib/ms_rest/credentials/token_credentials.rb
Overview
Class which keeps functionality and date for performing OAuth (token based) authentication.
Constant Summary
Constants inherited from ServiceClientCredentials
ServiceClientCredentials::AUTHORIZATION
Instance Method Summary collapse
-
#initialize(*args) ⇒ TokenCredentials
constructor
Creates and initialize new instance of the TokenCredentials class.
-
#sign_request(request) ⇒ Net::HTTPRequest
Attaches OAuth authentication header to the given HTTP request.
Constructor Details
#initialize(*args) ⇒ TokenCredentials
Creates and initialize new instance of the TokenCredentials class.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ms_rest/credentials/token_credentials.rb', line 24 def initialize(*args) if (args.size == 1) if args[0].respond_to? :get_authentication_header @token_provider = args[0] elsif args[0].is_a? String @token_provider = StringTokenProvider.new args[0], DEFAULT_SCHEME else fail ArgumentError, 'Invalid argument was passed, is can be either TokenProvider or token' end elsif (args.size == 2) token = args[0] token_type = args[1] @token_provider = StringTokenProvider.new token, token_type else fail ArgumentError, 'Invalid number of parameters was passed to TokenCredentials constructor, valid number is 1 or 2' end end |
Instance Method Details
#sign_request(request) ⇒ Net::HTTPRequest
Attaches OAuth authentication header to the given HTTP request.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ms_rest/credentials/token_credentials.rb', line 47 def sign_request(request) super(request) header = @token_provider.get_authentication_header if (request.respond_to?(:request_headers)) request.request_headers[AUTHORIZATION] = header elsif request.respond_to?(:headers) request.headers[AUTHORIZATION] = header else fail ArgumentError, 'Incorrect request object was provided' end end |