class GitDuplicator::Helpers::AuthorizationHeader
Generates authentication header
Constants
- BASIC_KEYS
- OAUTH2_KEYS
- OAUTH_KEYS
Attributes
credentials[RW]
request_method[RW]
request_params[RW]
request_url[RW]
Public Class Methods
new(credentials, request)
click to toggle source
@param [Hash] credentials @option credentials [Symbol] :oauth2_token used in oAuth2 authentication @option credentials [Symbol] :consumer_key used in oAuth authentication @option credentials [Symbol] :consumer_secret used in oAuth authentication @option credentials [Symbol] :token used in oAuth authentication @option credentials [Symbol] :token_secret used in oAuth authentication @option credentials [Symbol] :username used in basic authentication @option credentials [Symbol] :password used in basic authentication @param [Hash] request used in generating oauth headers @option request [Symbol] :method @option request [String] :url @option request [Array] :params
# 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
Public Instance Methods
generate()
click to toggle source
Generate the header
# 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
Private Instance Methods
base64_username_password()
click to toggle source
# File lib/git_duplicator/helpers/authorization_header.rb, line 65 def base64_username_password Base64.encode64("#{credentials[:username]}" \ ":#{credentials[:password]}") end
basic_authenticaion_header()
click to toggle source
# File lib/git_duplicator/helpers/authorization_header.rb, line 56 def basic_authenticaion_header "Basic #{base64_username_password}" end
exists?(list)
click to toggle source
# File lib/git_duplicator/helpers/authorization_header.rb, line 48 def exists?(list) list.all? { |value| credentials.keys.include?(value) } end
oauth2_header()
click to toggle source
# File lib/git_duplicator/helpers/authorization_header.rb, line 52 def oauth2_header "token #{credentials[:oauth2_token]}" end
oauth_header()
click to toggle source
# File lib/git_duplicator/helpers/authorization_header.rb, line 60 def oauth_header SimpleOAuth::Header.new(request_method, request_url, request_params, credentials).to_s end