vrag86 / perl-net-google-oauth

1 stars 2 forks source link

Localhost refused to connect when trying to generate access token #2

Open hakonhagland opened 4 years ago

hakonhagland commented 4 years ago

I am trying to create an access token for Google Drive API:

my $oauth = Net::Google::OAuth->new(
    -client_id          => $CLIENT_ID,
    -client_secret      => $CLIENT_SECRET,
);
$oauth->generateAccessToken(
    -scope      => 'drive',
    -email      => 'hakon.hagland@gmail.com',
);

This gives the following output in the terminal:

Please open this URL in your browser: 
https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&client_id=[[MY_CLIENT_ID]]login_hint=hakon.hagland%40gmail.com&nonce=644344-712751-15770&redirect_uri=http%3A%2F%2Flocalhost%3A8000&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=uniq_state_84496

If I paste the link into Google Chrome (Ubuntu 20.04) I get the following screen shot:

sign_in

If I click the "Allow" button, I get this page:

localhost

hakonhagland commented 4 years ago

According to this page using redirect_uri=http://localhost:8000 requires my application to be listening on the local web server. But I think I am not listening since I am just running the script from the terminal window. However, the above linked page then suggest to use a redirect of urn:ietf:wg:oauth:2.0:oob instead. This value indicates that Google's authorization server should return the authorization code in the browser's title bar.