morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

in order to get a better understanding of OAuth2 I am trying to call the google-calendar-api but cannot make it work...

I have registered an application with my google-account and so have a client-id and a client-secret.

What I am trying to do works in the Google OAuth2 Playground but what happens in my case is that the OAuth2-dance seems to work ok - i.e. I get an access-code and can convert that into a token but when I try to call the api using the token I always end up with a 403 "Access not configured".

Here is what I am trying:

use Net::OAuth2::Profile::WebServer; use Data::Dumper; use Mojolicious::Lite; my $auth = Net::OAuth2::Profile::WebServer->new ( name => 'my_app_name' , client_id => 'my_client_id' , client_secret => 'my_client_secret' , site => 'https://accounts.google.com' , scope => 'https://www.googleapis.com/auth/calend +ar' , authorize_path => '/o/oauth2/auth' , access_token_path => '/o/oauth2/token' , redirect_uri => 'http://localhost/oauth2callback' ); get '/go' => sub { my $self = shift; my $uri = $auth->authorize; $self->redirect_to($uri); }; get '/oauth2callback' => sub { my $self = shift; my $auth_code = $self->param("code"); my $token =$auth->get_access_token($auth_code); my $res = $token->get("https://www.googleapis.com/calendar/v3/users/ +me/settings"); $self->stash( ac => $auth_code, to => Dumper($token), res => Dumper( +$res) ); $self->render("callback"); }; app->start; __DATA__ @@ callback.html.ep <pre><%= $ac %></pre> <pre><%= $to %></pre> <pre><%= $res %></pre>
As the code is pretty trivial what I am missing is probably something simple, but I can't think of anything at the moment...

Many thanks!