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/calendar' , 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
<%= $ac %>
<%= $to %>
<%= $res %>