Skip to content

Commit

Permalink
Add "X-CSRFToken" header for new Docker Hub API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tianon committed Dec 24, 2018
1 parent f150010 commit c35e6aa
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion push.pl
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,22 @@

my $token = $login->res->json->{token};

my $csrf;
for my $cookie (@{ $login->res->cookies }) {
if ($cookie->name eq 'csrftoken') {
$csrf = $cookie->value;
last;
}
}
die 'missing CSRF token' unless defined $csrf;

my $attemptLogin = $ua->post('https://hub.docker.com/attempt-login/' => {} => json => { jwt => $token });
die 'attempt-login failed' unless $attemptLogin->success;

my $authorizationHeader = { Authorization => "JWT $token" };
my $authorizationHeader = {
Authorization => "JWT $token",
'X-CSRFToken' => $csrf,
};

my $userData = $ua->get('https://hub.docker.com/v2/user/' => $authorizationHeader);
die 'user failed' unless $userData->success;
Expand Down

0 comments on commit c35e6aa

Please sign in to comment.