API-Google
view release on metacpan or search on metacpan
},
"name" : "API-Google",
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Config::JSON" : "0",
"Crypt::JWT" : "0",
"Data::Dumper" : "0",
"Mojo::UserAgent" : "0",
"Mojo::Util" : "0",
"Mojolicious::Commands" : "0",
"Mojolicious::Lite" : "0",
"Mojolicious::Plugin::OAuth2" : "0",
"Net::EmptyPort" : "0",
"Tie::File" : "0",
"feature" : "0",
"bugtracker" : {
"web" : "https://github.com/pavelsr/API-Google/issues"
},
"repository" : {
"type" : "git",
"url" : "git://github.com/pavelsr/API-Google.git",
"web" : "https://github.com/pavelsr/API-Google"
}
},
"version" : "0.12",
"x_serialization_backend" : "Cpanel::JSON::XS version 3.0225"
}
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.009, CPAN::Meta::Converter version 2.150001'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: API-Google
requires:
Config::JSON: '0'
Crypt::JWT: '0'
Data::Dumper: '0'
Mojo::UserAgent: '0'
Mojo::Util: '0'
Mojolicious::Commands: '0'
Mojolicious::Lite: '0'
Mojolicious::Plugin::OAuth2: '0'
Net::EmptyPort: '0'
Tie::File: '0'
feature: '0'
Makefile.PL view on Meta::CPAN
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "API-Google",
"EXE_FILES" => [
"bin/goauth"
],
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.006",
"NAME" => "API::Google",
"PREREQ_PM" => {
"Config::JSON" => 0,
"Crypt::JWT" => 0,
"Data::Dumper" => 0,
"Mojo::UserAgent" => 0,
"Mojo::Util" => 0,
"Mojolicious::Commands" => 0,
"Mojolicious::Lite" => 0,
"Mojolicious::Plugin::OAuth2" => 0,
"Net::EmptyPort" => 0,
"Tie::File" => 0,
"feature" => 0,
Makefile.PL view on Meta::CPAN
"Test::More" => 0
},
"VERSION" => "0.12",
"test" => {
"TESTS" => "t/*.t"
}
);
my %FallbackPrereqs = (
"Config::JSON" => 0,
"Crypt::JWT" => 0,
"Data::Dumper" => 0,
"Mojo::UserAgent" => 0,
"Mojo::Util" => 0,
"Mojolicious::Commands" => 0,
"Mojolicious::Lite" => 0,
"Mojolicious::Plugin::OAuth2" => 0,
"Net::EmptyPort" => 0,
"Test::More" => 0,
"Tie::File" => 0,
#!perl
package goauth;
$goauth::VERSION = '0.12';
# ABSTRACT: CLI tool for easily getting of Google API access tokens. Supports multiple users
use Mojolicious::Commands;
use Data::Dumper;
use Config::JSON;
use Tie::File;
use feature 'say';
use Net::EmptyPort qw(empty_port);
my $filename;
if ($ARGV[0]) {
$filename = $ARGV[0];
} else {
$filename = 'config.json';
}
if (-e $filename) {
say "File $filename exists";
input_if_not_exists(['gapi/client_id', 'gapi/client_secret']);
runserver();
} else {
say "JSON file $filename with API tokens not found. Creating new file...";
setup();
runserver();
}
sub setup {
my $oauth = {};
say "Obtain app client_id and client_secret from http://console.developers.google.com/";
print "client_id: ";
chomp ($oauth->{client_id} = <STDIN>);
print "client_secret: ";
chomp ($oauth->{client_secret} = <STDIN>);
my $tokensfile = Config::JSON->create($filename);
$tokensfile->set('gapi/client_id', $oauth->{client_id});
$tokensfile->set('gapi/client_secret', $oauth->{client_secret});
say 'OAuth details was updated!';
# Remove comment for Mojolicious::Plugin::JSONConfig compatibility
tie my @array, 'Tie::File', $filename or die $!;
shift @array;
untie @array;
};
sub input_if_not_exists {
my $fields = shift;
my $config = Config::JSON->new($filename);
for my $i (@$fields) {
if (!defined $config->get($i) ) {
print "$i: ";
chomp (my $val = <STDIN>);
$config->set($i, $val);
}
}
}
sub runserver {
[PodWeaver]
[ReadmeAnyFromPod]
type = markdown
filename = README.md
location = build
[CopyFilesFromBuild]
copy = README.md
[MetaJSON]
[GitHub::Meta]
[ChangelogFromGit]
lib/API/Google.pm view on Meta::CPAN
package API::Google;
$API::Google::VERSION = '0.12';
use Data::Dumper;
# ABSTRACT: Perl library for easy access to Google services via their API
use strict;
use warnings;
use Mojo::UserAgent;
use Config::JSON;
use Data::Dumper;
sub new {
my ($class, $params) = @_;
my $h = {};
if ($params->{tokensfile}) {
$h->{tokensfile} = Config::JSON->new($params->{tokensfile});
} else {
die 'no json file specified!';
}
$h->{ua} = Mojo::UserAgent->new();
$h->{debug} = $params->{debug};
$h->{max_refresh_attempts} = $params->{max_refresh_attempts} || 5;
return bless $h, $class;
}
lib/API/Google/Server.pm view on Meta::CPAN
#!perl
package API::Google::Server;
$API::Google::Server::VERSION = '0.12';
# ABSTRACT: Mojolicious::Lite web server for getting Google API tokens via Oauth 2.0
use Mojolicious::Lite;
use Data::Dumper;
use Config::JSON;
use Tie::File;
use Crypt::JWT qw(decode_jwt);
use feature 'say';
use Mojo::Util 'getopt';
use Mojolicious::Plugin::OAuth2;
# use Mojo::JWT;
# sub return_json_filename {
# use Cwd;
# my $cwd = getcwd;
# opendir my $dir, $cwd or die "Cannot open directory: $!";
# my @files = readdir $dir;
# my @j = grep { $_ =~ /\w+.json/ } @files;
# return $j[0];
# }
# my $f = return_json_filename();
my $config = Config::JSON->new($ENV{'GOAUTH_TOKENSFILE'});
delete $ENV{'GOAUTH_TOKENSFILE'};
# authorize_url and token_url can be retrieved from OAuth discovery document
# https://github.com/marcusramberg/Mojolicious-Plugin-OAuth2/issues/52
plugin "OAuth2" => {
google => {
key => $config->get('gapi/client_id'), # $config->{gapi}{client_id},
secret => $config->get('gapi/client_secret'), #$config->{gapi}{client_secret},
authorize_url => 'https://accounts.google.com/o/oauth2/v2/auth?response_type=code',
token_url => 'https://www.googleapis.com/oauth2/v4/token'
lib/API/Google/Server.pm view on Meta::CPAN
$hash->{redirect_uri} = $c->url_for->to_abs->to_string;
$hash->{client_id} = $config->get('gapi/client_id');
$hash->{client_secret} = $config->get('gapi/client_secret');
$hash->{grant_type} = 'authorization_code';
my $tokens = $c->ua->post('https://www.googleapis.com/oauth2/v4/token' => form => $hash)->res->json;
return $tokens;
};
# =method get_all_google_jwk_keys
# Get all Google JWK keys for validation of JSON Web Token
# Check https://jwt.io/ and https://developers.google.com/identity/protocols/OpenIDConnect#validatinganidtoken for more details
# return arrayref
# =cut
# helper get_all_google_jwk_keys => sub {
# my $c = shift;
# my $certs = $c->ua->get('https://www.googleapis.com/oauth2/v3/certs')->res->json;
( run in 0.747 second using v1.01-cache-2.11-cpan-140bd7fdf52 )