Class: GitDuplicator::Helpers::AuthorizationHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/git_duplicator/helpers/authorization_header.rb

Overview

Generates authentication header

Constant Summary collapse

OAUTH2_KEYS =
[:oauth2_token]
OAUTH_KEYS =
[:consumer_key, :consumer_secret, :token, :token_secret]
BASIC_KEYS =
[:username, :password]

Instance Method Summary collapse

Constructor Details

#initialize(credentials, request) ⇒ AuthorizationHeader

Returns a new instance of AuthorizationHeader.

Parameters:

  • credentials (Hash)
  • request (Hash)

    used in generating oauth headers

Options Hash (credentials):

  • :oauth2_token (Symbol)

    used in oAuth2 authentication

  • :consumer_key (Symbol)

    used in oAuth authentication

  • :consumer_secret (Symbol)

    used in oAuth authentication

  • :token (Symbol)

    used in oAuth authentication

  • :token_secret (Symbol)

    used in oAuth authentication

  • :username (Symbol)

    used in basic authentication

  • :password (Symbol)

    used in basic authentication

Options Hash (request):

  • :method (Symbol)
  • :url (String)
  • :params (Array)


24
25
26
27
28
29
# File 'lib/git_duplicator/helpers/authorization_header.rb', line 24

def initialize(credentials, request)
  self.credentials = credentials
  self.request_method = request.fetch(:method)
  self.request_url = request.fetch(:url)
  self.request_params = request.fetch(:params) { [] }
end

Instance Method Details

#generateObject

Generate the header



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/git_duplicator/helpers/authorization_header.rb', line 32

def generate
  if exists?(self.class::OAUTH2_KEYS)
    oauth2_header
  elsif exists?(self.class::OAUTH_KEYS)
    oauth_header
  elsif exists?(self.class::BASIC_KEYS)
    basic_authenticaion_header
  else
    fail ArgumentError, 'Proper authentication keys are missing'
  end
end