class MsRest::BasicAuthenticationCredentials

Constants

DEFAULT_SCHEME

Attributes

password[RW]

@return [String] password for authentication.

scheme[RW]

@return [String] the scheme for composing credentials.

user_name[RW]

@return [String] the username for authentication.

Public Class Methods

new(user_name, password, scheme = DEFAULT_SCHEME) click to toggle source

Creates and initialize new instance of the BasicAuthenticationCredentials class. @param user_name [String] the username for authentication. @param password [String] the password for authentication. @param scheme = DEFAULT_SCHEME [String] the scheme for composing credentials.

# 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

Public Instance Methods

sign_request(request) click to toggle source

Attaches basic authentication header to the given HTTP request. @param request [Net::HTTPRequest] the request authentication header needs to be attached to.

@return [Net::HTTPRequest] request with attached authentication header.

Calls superclass method
# 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