mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-04 00:00:37 -04:00
reworking auth APIs for a future 1.0 refactoring
This commit is contained in:
parent
be06032649
commit
c86f4be1a7
@ -7,7 +7,7 @@ module HTTPX
|
|||||||
#
|
#
|
||||||
# https://gitlab.com/honeyryderchuck/httpx/wikis/Authentication#basic-authentication
|
# https://gitlab.com/honeyryderchuck/httpx/wikis/Authentication#basic-authentication
|
||||||
#
|
#
|
||||||
module BasicAuthentication
|
module BasicAuth
|
||||||
class << self
|
class << self
|
||||||
def load_dependencies(_klass)
|
def load_dependencies(_klass)
|
||||||
require_relative "authentication/basic"
|
require_relative "authentication/basic"
|
||||||
@ -19,12 +19,12 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
def basic_authentication(user, password)
|
def basic_auth(user, password)
|
||||||
authentication(Authentication::Basic.new(user, password).authenticate)
|
authentication(Authentication::Basic.new(user, password).authenticate)
|
||||||
end
|
end
|
||||||
alias_method :basic_auth, :basic_authentication
|
alias_method :basic_authentication, :basic_auth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
register_plugin :basic_authentication, BasicAuthentication
|
register_plugin :basic_authentication, BasicAuth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ module HTTPX
|
|||||||
#
|
#
|
||||||
# https://gitlab.com/honeyryderchuck/httpx/wikis/Authentication#authentication
|
# https://gitlab.com/honeyryderchuck/httpx/wikis/Authentication#authentication
|
||||||
#
|
#
|
||||||
module DigestAuthentication
|
module DigestAuth
|
||||||
DigestError = Class.new(Error)
|
DigestError = Class.new(Error)
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
@ -58,6 +58,6 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
register_plugin :digest_authentication, DigestAuthentication
|
register_plugin :digest_authentication, DigestAuth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ module HTTPX
|
|||||||
#
|
#
|
||||||
# https://gitlab.com/honeyryderchuck/httpx/wikis/Authentication#ntlm-authentication
|
# https://gitlab.com/honeyryderchuck/httpx/wikis/Authentication#ntlm-authentication
|
||||||
#
|
#
|
||||||
module NTLMAuthentication
|
module NTLMAuth
|
||||||
class << self
|
class << self
|
||||||
def load_dependencies(_klass)
|
def load_dependencies(_klass)
|
||||||
require_relative "authentication/ntlm"
|
require_relative "authentication/ntlm"
|
||||||
@ -53,6 +53,6 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
register_plugin :ntlm_authentication, NTLMAuthentication
|
register_plugin :ntlm_authentication, NTLMAuth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,9 +13,9 @@ module HTTPX
|
|||||||
| (options) { (Session) -> void } -> void
|
| (options) { (Session) -> void } -> void
|
||||||
|
|
||||||
def plugin: (:authentication, ?options) -> Plugins::sessionAuthentication
|
def plugin: (:authentication, ?options) -> Plugins::sessionAuthentication
|
||||||
| (:basic_authentication, ?options) -> Plugins::sessionBasicAuthentication
|
| (:basic_authentication, ?options) -> Plugins::sessionBasicAuth
|
||||||
| (:digest_authentication, ?options) -> Plugins::sessionDigestAuthentication
|
| (:digest_authentication, ?options) -> Plugins::sessionDigestAuth
|
||||||
| (:ntlm_authentication, ?options) -> Plugins::sessionNTLMAuthentication
|
| (:ntlm_authentication, ?options) -> Plugins::sessionNTLMAuth
|
||||||
| (:aws_sdk_authentication, ?options) -> Plugins::sessionAwsSdkAuthentication
|
| (:aws_sdk_authentication, ?options) -> Plugins::sessionAwsSdkAuthentication
|
||||||
| (:compression, ?options) -> Session
|
| (:compression, ?options) -> Session
|
||||||
| (:cookies, ?options) -> Plugins::sessionCookies
|
| (:cookies, ?options) -> Plugins::sessionCookies
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module HTTPX
|
module HTTPX
|
||||||
module Plugins
|
module Plugins
|
||||||
module BasicAuthentication
|
module BasicAuth
|
||||||
def self.load_dependencies: (singleton(Session)) -> void
|
def self.load_dependencies: (singleton(Session)) -> void
|
||||||
|
|
||||||
def self.configure: (singleton(Session)) -> void
|
def self.configure: (singleton(Session)) -> void
|
||||||
@ -10,6 +10,6 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
type sessionBasicAuthentication = sessionAuthentication & Authentication::InstanceMethods & BasicAuthentication::InstanceMethods
|
type sessionBasicAuth = sessionAuthentication & Authentication::InstanceMethods & BasicAuth::InstanceMethods
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module HTTPX
|
module HTTPX
|
||||||
module Plugins
|
module Plugins
|
||||||
module DigestAuthentication
|
module DigestAuth
|
||||||
DigestError: singleton(Error)
|
DigestError: singleton(Error)
|
||||||
|
|
||||||
interface _DigestOptions
|
interface _DigestOptions
|
||||||
@ -16,6 +16,6 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
type sessionDigestAuthentication = sessionAuthentication & DigestAuthentication::InstanceMethods
|
type sessionDigestAuth = sessionAuthentication & DigestAuth::InstanceMethods
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module HTTPX
|
module HTTPX
|
||||||
module Plugins
|
module Plugins
|
||||||
module NTLMAuthentication
|
module NTLMAuth
|
||||||
|
|
||||||
interface _NTLMOptions
|
interface _NTLMOptions
|
||||||
def ntlm: () -> Authentication::Ntlm?
|
def ntlm: () -> Authentication::Ntlm?
|
||||||
@ -16,6 +16,6 @@ module HTTPX
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
type sessionNTLMAuthentication = sessionAuthentication & NTLMAuthentication::InstanceMethods
|
type sessionNTLMAuth = sessionAuthentication & NTLMAuth::InstanceMethods
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,13 +12,13 @@ module Requests
|
|||||||
no_auth_response.close
|
no_auth_response.close
|
||||||
|
|
||||||
session = HTTPX.plugin(:basic_authentication)
|
session = HTTPX.plugin(:basic_authentication)
|
||||||
response = session.basic_authentication(user, pass).get(basic_auth_uri)
|
response = session.basic_auth(user, pass).get(basic_auth_uri)
|
||||||
verify_status(response, 200)
|
verify_status(response, 200)
|
||||||
body = json_body(response)
|
body = json_body(response)
|
||||||
verify_header(body, "authenticated", true)
|
verify_header(body, "authenticated", true)
|
||||||
verify_header(body, "user", user)
|
verify_header(body, "user", user)
|
||||||
|
|
||||||
invalid_response = session.basic_authentication(user, "fake").get(basic_auth_uri)
|
invalid_response = session.basic_auth(user, "fake").get(basic_auth_uri)
|
||||||
verify_status(invalid_response, 401)
|
verify_status(invalid_response, 401)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ module Requests
|
|||||||
|
|
||||||
def test_plugin_digest_authentication
|
def test_plugin_digest_authentication
|
||||||
session = HTTPX.plugin(:digest_authentication).with_headers("cookie" => "fake=fake_value")
|
session = HTTPX.plugin(:digest_authentication).with_headers("cookie" => "fake=fake_value")
|
||||||
response = session.digest_authentication(user, pass).get(digest_auth_uri)
|
response = session.digest_auth(user, pass).get(digest_auth_uri)
|
||||||
verify_status(response, 200)
|
verify_status(response, 200)
|
||||||
body = json_body(response)
|
body = json_body(response)
|
||||||
verify_header(body, "authenticated", true)
|
verify_header(body, "authenticated", true)
|
||||||
@ -36,7 +36,7 @@ module Requests
|
|||||||
%w[SHA1 SHA2 SHA256 SHA384 SHA512 RMD160].each do |alg|
|
%w[SHA1 SHA2 SHA256 SHA384 SHA512 RMD160].each do |alg|
|
||||||
define_method "test_plugin_digest_authentication_#{alg}" do
|
define_method "test_plugin_digest_authentication_#{alg}" do
|
||||||
session = HTTPX.plugin(:digest_authentication).with_headers("cookie" => "fake=fake_value")
|
session = HTTPX.plugin(:digest_authentication).with_headers("cookie" => "fake=fake_value")
|
||||||
response = session.digest_authentication(user, pass).get("#{digest_auth_uri}/#{alg}")
|
response = session.digest_auth(user, pass).get("#{digest_auth_uri}/#{alg}")
|
||||||
verify_status(response, 200)
|
verify_status(response, 200)
|
||||||
body = json_body(response)
|
body = json_body(response)
|
||||||
verify_header(body, "authenticated", true)
|
verify_header(body, "authenticated", true)
|
||||||
@ -57,7 +57,7 @@ module Requests
|
|||||||
verify_status(no_auth_response, 401)
|
verify_status(no_auth_response, 401)
|
||||||
no_auth_response.close
|
no_auth_response.close
|
||||||
|
|
||||||
response = http.ntlm_authentication("user", "password").get(uri)
|
response = http.ntlm_auth("user", "password").get(uri)
|
||||||
verify_status(response, 200)
|
verify_status(response, 200)
|
||||||
|
|
||||||
# invalid_response = http.ntlm_authentication("user", "fake").get(uri)
|
# invalid_response = http.ntlm_authentication("user", "fake").get(uri)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
-
|
-
|
||||||
name: BasicAuthentication
|
name: BasicAuth
|
||||||
path: Authentication.html#basic-authentication
|
path: Authentication.html#basic-authentication
|
||||||
description: API and support for Basic Authentication.
|
description: API and support for Basic Authentication.
|
||||||
-
|
-
|
||||||
|
Loading…
x
Reference in New Issue
Block a user