NAME
Mojo::UserAgent::Role::Signature - Role for Mojo::UserAgent that automatically signs request transactions
SYNOPSIS
use
Mojo::UserAgent;
my
$ua
= Mojo::UserAgent->with_roles(
'+Signature'
)->new;
$ua
->initialize_signature(
SomeService
=> {
%args
});
my
$tx
=
$ua
->get(
'/api/for/some/service'
);
say
$tx
->req->headers->authorization;
DESCRIPTION
Mojo::UserAgent::Role::Signature is a role for the full featured non-blocking I/O HTTP and WebSocket user agent Mojo::UserAgent, that automatically signs request transactions.
This module modifies the Mojo::UserAgent by wrapping "around" in Role::Tiny the "build_tx" in Mojo::UserAgent method with "apply_signature" signing the final built transaction using the object instance set in the "signature" attribute that is this module adds to the Mojo::UserAgent class.
ATTRIBUTES
signature
$signature
=
$ua
->signature;
$ua
=
$ua
->signature(SomeService->new);
If this attribute is not defined, the method modifier provided by this role will have no effect on the transaction being built by Mojo::UserAgent.
signature_namespaces
$namespaces
=
$ua
->signature_namespaces;
$ua
=
$ua
->signature_namespaces([
'Mojo::UserAgent::Signature'
]);
Namespaces to load signature from, defaults to Mojo::UserAgent::Signature
.
# Add another namespace to load signature from
push
@{
$ua
->namespaces},
'MyApp::Signature'
;
METHODS
Mojo::UserAgent::Role::Signature inherits all methods from Mojo::Base and implements the following new ones.
initialize_signature
$ua
->initialize_signature(
'some_service'
);
$ua
->initialize_signature(
'some_service'
,
foo
=> 23);
$ua
->initialize_signature(
'some_service'
, {
foo
=> 23});
$ua
->initialize_signature(
'SomeService'
);
$ua
->initialize_signature(
'SomeService'
,
foo
=> 23);
$ua
->initialize_signature(
'SomeService'
, {
foo
=> 23});
$ua
->initialize_signature(
'MyApp::Signature::SomeService'
);
$ua
->initialize_signature(
'MyApp::Signature::SomeService'
,
foo
=> 23);
$ua
->initialize_signature(
'MyApp::Signature::SomeService'
, {
foo
=> 23});
Load a signature from the configured namespaces or by full module name and run init, optional arguments are passed through.
load_signature
my
$signature
=
$ua
->load_signature(
'some_service'
);
my
$signature
=
$ua
->load_signature(
'SomeService'
);
my
$signature
=
$ua
->load_signature(
'MyApp::Signature::SomeService'
);
Load a signature from the configured namespaces or by full module name. Will fallback to Mojo::UserAgent::Signature::None if the specified signature cannot be loaded.
COPYRIGHT AND LICENSE
Copyright (C) 2020, Stefan Adams.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
SEE ALSO
https://github.com/stefanadams/mojo-useragent-role-signature, Mojo::UserAgent.