Skip to content

Commit

Permalink
Remove v2 unsuported auth methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jacegu committed Dec 14, 2015
1 parent 387de1d commit 4346ce3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 43 deletions.
18 changes: 3 additions & 15 deletions lib/dnsimple/client.rb
Expand Up @@ -11,10 +11,8 @@ class Client
include Dnsimple::Compatibility

HEADER_2FA_STRICT = "X-DNSimple-2FA-Strict"
HEADER_API_TOKEN = "X-DNSimple-Token"
HEADER_DOMAIN_API_TOKEN = "X-DNSimple-Domain-Token"
HEADER_OTP_TOKEN = "X-DNSimple-OTP"
HEADER_EXCHANGE_TOKEN = "X-DNSimple-OTP-Token"
HEADER_OAUTH_ACCESS_TOKEN = "Authorization"


Expand All @@ -37,12 +35,6 @@ def self.versioned(path)
# @!attribute password
# @see http://developer.dnsimple.com/authentication/
# @return [String] DNSimple password for Basic Authentication
# @!attribute exchange_token
# @see http://developer.dnsimple.com/authentication/
# @return [String] Exchange Token for Basic Authentication with 2FA
# @!attribute api_token
# @see http://developer.dnsimple.com/authentication/
# @return [String] API access token for authentication
# @!attribute domain_api_token
# @see http://developer.dnsimple.com/authentication/
# @return [String] Domain API access token for authentication
Expand All @@ -57,8 +49,8 @@ def self.versioned(path)
# @!attribute proxy
# @return [String,nil] Configure address:port values for proxy server

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:oauth_client_id, :oauth_client_secret, :oauth_access_token, :user_agent, :proxy
attr_accessor :api_endpoint, :username, :password, :domain_api_token, :oauth_access_token,
:oauth_client_id, :oauth_client_secret, :user_agent, :proxy


def initialize(options = {})
Expand Down Expand Up @@ -179,14 +171,10 @@ def base_options
options.merge!(http_proxyaddr: address, http_proxyport: port)
end

if exchange_token
options[:basic_auth] = { username: exchange_token, password: "x-2fa-basic" }
elsif password
if password
options[:basic_auth] = { username: username, password: password }
elsif domain_api_token
options[:headers][HEADER_DOMAIN_API_TOKEN] = domain_api_token
elsif api_token
options[:headers][HEADER_API_TOKEN] = "#{username}:#{api_token}"
elsif oauth_access_token
options[:headers][HEADER_OAUTH_ACCESS_TOKEN] = "Bearer #{oauth_access_token}"
else
Expand Down
2 changes: 1 addition & 1 deletion lib/dnsimple/compatibility.rb
Expand Up @@ -43,4 +43,4 @@ def delete(*args)

end

end
end
22 changes: 4 additions & 18 deletions lib/dnsimple/default.rb
Expand Up @@ -18,12 +18,10 @@ def keys
:api_endpoint,
:username,
:password,
:exchange_token,
:api_token,
:domain_api_token,
:oauth_access_token,
:oauth_client_id,
:oauth_client_secret,
:oauth_access_token,
:user_agent,
:proxy,
]
Expand Down Expand Up @@ -53,22 +51,16 @@ def password
ENV['DNSIMPLE_PASSWORD']
end

# Default DNSimple Exchange Token for Basic Auth from ENV
# @return [String]
def exchange_token
ENV['DNSIMPLE_API_EXCHANGE_TOKEN']
end

# Default DNSimple Domain API Token for Token Auth from ENV
# @return [String]
def domain_api_token
ENV['DNSIMPLE_API_DOMAIN_TOKEN']
end

# Default DNSimple API Token for Token Auth from ENV
# Default DNSimple OAuth access token for OAuth authentication from ENV
# @return [String]
def api_token
ENV['DNSIMPLE_API_TOKEN']
def oauth_access_token
ENV['DNSIMPLE_OAUTH_ACCESS_TOKEN']
end

# Default DNSimple OAuth client ID for OAuth authentication from ENV
Expand All @@ -83,12 +75,6 @@ def oauth_client_secret
ENV['DNSIMPLE_OAUTH_CLIENT_SECRET']
end

# Default DNSimple OAuth access token for OAuth authentication from ENV
# @return [String]
def oauth_access_token
ENV['DNSIMPLE_OAUTH_ACCESS_TOKEN']
end

# Default User-Agent header string from ENV or {USER_AGENT}
# @return [String]
def user_agent
Expand Down
9 changes: 0 additions & 9 deletions spec/dnsimple/client_spec.rb
Expand Up @@ -60,15 +60,6 @@
with { |req| req.headers["X-Dnsimple-Token"] == "user:token" }
end

it "uses HTTP authentication via exchange token if there's an exchange token provided" do
stub_request(:any, %r[/test])

subject = described_class.new(username: "user", password: "pass", exchange_token: "exchange-token")
subject.execute(:get, "test", {})

expect(WebMock).to have_requested(:get, "https://exchange-token:x-2fa-basic@api.dnsimple.com/test")
end

it "uses OAuth access token if there's an access token provided" do
stub_request(:any, %r[/test])

Expand Down

0 comments on commit 4346ce3

Please sign in to comment.