summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2011-05-06 09:30:03 +0200
committerfranck cuny <franck@lumberjaph.net>2011-07-26 13:19:59 +0200
commit343b23a4cc9bfa53175f4ac6ec99a07ce55e9b8f (patch)
tree087e8109633417ed472d0240d1d841be3d7b96d2
parentupdate changes (diff)
downloadnet-http-spore-343b23a4cc9bfa53175f4ac6ec99a07ce55e9b8f.tar.gz
new middleware
Signed-off-by: franck cuny <franck@lumberjaph.net>
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Auth/Header.pm32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/Net/HTTP/Spore/Middleware/Auth/Header.pm b/lib/Net/HTTP/Spore/Middleware/Auth/Header.pm
new file mode 100644
index 0000000..95cff9e
--- /dev/null
+++ b/lib/Net/HTTP/Spore/Middleware/Auth/Header.pm
@@ -0,0 +1,32 @@
+package Net::HTTP::Spore::Middleware::Auth::Header;
+
+# ABSTRACT: middleware for authentication with specific header
+
+use Moose;
+extends 'Net::HTTP::Spore::Middleware::Auth::Auth';
+
+has header_name => (isa => 'Str', is => 'rw', required => 1);
+has header_value => (isa => 'Str', is => 'rw', required => 1);
+
+sub call {
+    my ($self, $req) = @_;
+
+    return unless $self->should_authenticate($req);
+
+    $req->header($self->header_name => $self->header_value);
+}
+
+1;
+
+=head1 SYNOPSIS
+
+    my $client = Net::HTTP::Spore->new_from_spec('api.json');
+    $client->enable(
+        'Auth::Header',
+        header_name  => 'X-API-Auth',
+        header_value => '12345'
+    );
+
+=head1 DESCRIPTION
+
+Net::HTTP::Spore::Middleware::Auth::Header is a middleware to handle authentication mechanism that requires a specific header name.