Class: MsRest::BasicAuthenticationCredentials
- Inherits:
-
ServiceClientCredentials
- Object
- ServiceClientCredentials
- MsRest::BasicAuthenticationCredentials
- Defined in:
- lib/ms_rest/credentials/basic_authentication_credentials.rb
Constant Summary
Constants inherited from ServiceClientCredentials
ServiceClientCredentials::AUTHORIZATION
Instance Method Summary collapse
-
#initialize(user_name, password, scheme = DEFAULT_SCHEME) ⇒ BasicAuthenticationCredentials
constructor
Creates and initialize new instance of the BasicAuthenticationCredentials class.
-
#sign_request(request) ⇒ Net::HTTPRequest
Attaches basic authentication header to the given HTTP request.
Constructor Details
#initialize(user_name, password, scheme = DEFAULT_SCHEME) ⇒ BasicAuthenticationCredentials
Creates and initialize new instance of the BasicAuthenticationCredentials class.
32 33 34 35 36 37 38 39 40 |
# File 'lib/ms_rest/credentials/basic_authentication_credentials.rb', line 32 def initialize(user_name, password, scheme = DEFAULT_SCHEME) fail ArgumentError, 'user_name cannot be nil' if user_name.nil? fail ArgumentError, 'password cannot be nil' if password.nil? fail ArgumentError, 'scheme cannot be nil' if scheme.nil? @user_name = user_name @password = password @scheme = scheme end |
Instance Method Details
#sign_request(request) ⇒ Net::HTTPRequest
Attaches basic authentication header to the given HTTP request.
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ms_rest/credentials/basic_authentication_credentials.rb', line 47 def sign_request(request) super(request) encodeCredentials = Base64.strict_encode64("#{user_name}:#{password}") credentials = "#{scheme} #{encodeCredentials}" if (request.respond_to?(:request_headers)) request.request_headers[AUTHORIZATION] = credentials elsif request.respond_to?(:headers) request.headers[AUTHORIZATION] = credentials else fail ArgumentError, 'Incorrect request object was provided' end end |