Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Feature/auth token #19

Merged
merged 5 commits into from

2 participants

Commits on Nov 28, 2012
  1. Removed the Git bundle for now

    authored
Commits on Jan 17, 2013
  1. @miquelruiz
Commits on Mar 13, 2013
Commits on Mar 16, 2013
  1. Cosmetic, code style

    authored
This page is out of date. Refresh to see the latest.
View
2  dist.ini
@@ -33,5 +33,3 @@ disable = Test::Kwalitee
disable = Test::Pod::LinkCheck
disable = PodCoverageTests
-[@Git]
-[Git::CommitBuild]
View
7 lib/Net/Amazon/S3.pm
@@ -144,6 +144,7 @@ has 'libxml' => ( is => 'rw', isa => 'XML::LibXML', required => 0 );
has 'ua' => ( is => 'rw', isa => 'LWP::UserAgent', required => 0 );
has 'err' => ( is => 'rw', isa => 'Maybe[Str]', required => 0 );
has 'errstr' => ( is => 'rw', isa => 'Maybe[Str]', required => 0 );
+has 'aws_session_token' => ( is => 'ro', isa => 'Str', required => 0 );
__PACKAGE__->meta->make_immutable;
@@ -174,6 +175,12 @@ only have come from you.
DO NOT INCLUDE THIS IN SCRIPTS OR APPLICATIONS YOU DISTRIBUTE. YOU'LL BE SORRY
+=item aws_session_token
+
+If you are using temporary credentials provided by the AWS Security Token
+Service, set the token here, and it will be added to the request in order to
+authenticate it.
+
=item secure
Set this to C<1> if you want to use SSL-encrypted connections when talking
View
7 lib/Net/Amazon/S3/HTTPRequest.pm
@@ -88,10 +88,17 @@ sub _add_auth_header {
my ( $self, $headers, $method, $path ) = @_;
my $aws_access_key_id = $self->s3->aws_access_key_id;
my $aws_secret_access_key = $self->s3->aws_secret_access_key;
+ my $aws_session_token = $self->s3->aws_session_token;
if ( not $headers->header('Date') ) {
$headers->header( Date => time2str(time) );
}
+
+ if ( not $headers->header('x-amz-security-token') and
+ defined $aws_session_token ) {
+ $headers->header( 'x-amz-security-token' => $aws_session_token );
+ }
+
my $canonical_string
= $self->_canonical_string( $method, $path, $headers );
my $encoded_canonical
View
35 t/03token.t
@@ -0,0 +1,35 @@
+#!perl
+use warnings;
+use strict;
+use lib 'lib';
+
+use Test::More;
+use Test::Exception;
+
+unless ( $ENV{'AWS_ACCESS_KEY_ID'} and
+ $ENV{'AWS_ACCESS_KEY_SECRET'} and
+ $ENV{'AWS_ACCESS_TOKEN'} ) {
+ plan skip_all =>
+ 'Need these vars in ENV: AWS_ACCESS_KEY_ID, ' .
+ 'AWS_ACCESS_KEY_SECRET, AWS_ACCESS_TOKEN';
+} else {
+ plan tests => 1 + 1;
+}
+
+use_ok('Net::Amazon::S3');
+
+my $aws_access_key_id = $ENV{'AWS_ACCESS_KEY_ID'};
+my $aws_secret_access_key = $ENV{'AWS_ACCESS_KEY_SECRET'};
+my $aws_session_token = $ENV{'AWS_ACCESS_TOKEN'};
+
+my $s3 = Net::Amazon::S3->new(
+ { aws_access_key_id => $aws_access_key_id,
+ aws_secret_access_key => $aws_secret_access_key,
+ aws_session_token => $aws_session_token,
+ retry => 1,
+ }
+);
+
+# list all buckets that i own
+my $response = $s3->buckets;
+ok($response, "Authentication with token succeded");
Something went wrong with that request. Please try again.