Sha256: 64da178ca3ce284868b3b2af54097b7f423d4752b2ddbfa5d40b858f24e28b4e

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

# Handles authentication using the Zerigo config.
class ZerigoDNS::Middleware::ZerigoAuth < Faraday::Middleware
  # Constructs new middleware instance
  def initialize app=nil, options={}
    @app = app
  end
  
  # Adds username & api key to Basic Auth header.
  # @param [Faraday::Request] env The request
  def call env
    # => Ruby 1.8.7 does not support Base64.strict_encode64
    auth_enc = Base64.encode64(formatted_login).gsub("\n", '')
    env.request_headers['Authorization'] = "Basic #{auth_enc}"
    @app.call(env)
  end
  
  private
  
  # Gets the user:password format from ZerigoDNS.config
  # @return [String] formatted login details
  def formatted_login
    [ZerigoDNS.config.user, ZerigoDNS.config.api_key].join(':')
  end
end

Faraday::Request.register_middleware zerigo_auth: ZerigoDNS::Middleware::ZerigoAuth

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zerigodns-1.1.0 lib/zerigodns/middleware/zerigo_auth.rb