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!


In reply to Problem with OAuth2 by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.