0

I'm trying to use Asana API with HTTP Basic Auth. The following program prints

{"errors":[{"message":"Not Authorized"}]}

It seems that LWP doesn't send the auth credentials to the server.

#!/usr/bin/perl

use v5.14.0;
use LWP;

my $ua = new LWP::UserAgent;
$ua->credentials('app.asana.com:443', 'realm', 'api_key_goes_here' => '');

my $res = $ua->get("https://app.asana.com/api/1.0/users/me");
say $res->decoded_content;
Sly
  • 415
  • 2
  • 8

1 Answers1

1

I've run into something similar (on a completely different service), and couldn't get it working. I think it's to do with a realm/hostname mismatch. As you note - if you hit that URL directly, from a web browser, you get the same answer (without an auth prompt).

But what I ended up doing instead:

my $request = HTTP::Request -> new ( 'GET' => 'https://path/to/surl' );
$request -> authorization_basic ( 'username', 'password' ); 

my $results = $user_agent -> request ( $request ); 
Sobrique
  • 52,974
  • 7
  • 60
  • 101