Docker-Registry
view release on metacpan or search on metacpan
lib/Docker/Registry/Auth/Gitlab.pm view on Meta::CPAN
my $res = $ua->get($uri);
if ($res->{success}) {
return decode_json($res->{content})->{token};
}
die "Unable to get token from gitlab!";
}
sub authorize {
my ($self, $request, $scope) = @_;
my $bearer_token = $self->get_bearer_token($scope);
$request->header('Authorization', 'Bearer ' . $bearer_token);
$request->header('Accept',
'application/vnd.docker.distribution.manifest.v2+json');
return $request;
}
__PACKAGE__->meta->make_immutable;
__END__
=head1 DESCRIPTION
Authenticate against gitlab registry
=head1 SYNOPSIS
use Docker::Registry::Auth::Gitlab;
use HTTP::Tiny;
my $auth = Docker::Registry::Auth::Gitlab->new(
username => 'foo',
access_token => 'bar',
);
my $req = $auth->authorize(HTTP::Request->new('GET', 'https://foo.bar.nl'));
my $res = HTTP::Tiny->new()->get($req);
=head1 ATTRIBUTES
=head2 username
Your username at gitlab.
=head2 access_token
The access token you get from
L<gitlab|https://gitlab.com/profile/personal_access_tokens> with
'read_registry' access.
=head2 repo
The repository you request access to.
=head2 jwt
The endpoint to request the JWT token from, defaults to
'https://gitlab.com/jwt/auth'. You can use a 'Str' or an URI object.
=head1 METHODS
=head2 get_bearer_token
The builder of the C<bearer_token> attribute.
=head2 authorize
Implements the method as required by L<Docker::Registry::Auth>. Add the
"Authorization" header to the request with the "Bearer" token.
=head2 SEE ALSO
L<Docker::Registry::Auth>, L<Docker::Registery::Types> and L<Docker::Registry::Gitlab>.
( run in 1.433 second using v1.01-cache-2.11-cpan-524268b4103 )