mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-11-27 00:03:01 -05:00
added #bearer_auth helper in authentication pluginn
This commit is contained in:
parent
3ec44fd56a
commit
17a26be1a9
@ -13,6 +13,10 @@ module HTTPX
|
||||
def authentication(token)
|
||||
with(headers: { "authorization" => token })
|
||||
end
|
||||
|
||||
def bearer_auth(token)
|
||||
authentication("Bearer #{token}")
|
||||
end
|
||||
end
|
||||
end
|
||||
register_plugin :authentication, Authentication
|
||||
|
||||
@ -3,6 +3,8 @@ module HTTPX
|
||||
module Authentication
|
||||
module InstanceMethods
|
||||
def authentication: (string token) -> instance
|
||||
|
||||
def bearer_auth: (string token) -> instance
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -3,6 +3,17 @@
|
||||
module Requests
|
||||
module Plugins
|
||||
module Authentication
|
||||
# Bearer Auth
|
||||
|
||||
def test_plugin_bearer_auth
|
||||
get_uri = build_uri("/get")
|
||||
session = HTTPX.plugin(:authentication)
|
||||
response = session.bearer_auth("TOKEN").get(get_uri)
|
||||
verify_status(response, 200)
|
||||
body = json_body(response)
|
||||
verify_header(body["headers"], "Authorization", "Bearer TOKEN")
|
||||
end
|
||||
|
||||
# Basic Auth
|
||||
|
||||
def test_plugin_basic_authentication
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user