Google-Auth
view release on metacpan or search on metacpan
bin/gcloud-auth.pl view on Meta::CPAN
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
use File::Spec;
use JSON::MaybeXS qw(encode_json decode_json);
use Log::Any qw($log);
use IO::Socket::INET;
use IO::Select;
use URI;
use Google::Auth;
use Google::Auth::ClientId;
use Google::Auth::UserAuthorizer;
use Google::Auth::Stores::FileTokenStore;
use Google::Auth::Exceptions;
my $VERSION = '0.01';
# Default Scopes for GCP
my @DEFAULT_SCOPES = (
'openid',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/cloud-platform',
'https://www.googleapis.com/auth/appengine.admin',
'https://www.googleapis.com/auth/sqlservice.login',
'https://www.googleapis.com/auth/compute',
'https://www.googleapis.com/auth/accounts.reauth'
);
unless (caller) {
run(@ARGV);
}
sub run {
my @args = @_;
my $help = 0;
my $man = 0;
my $verbose = 0;
my $client_id_file;
my $store_dir =
File::Spec->catdir($ENV{HOME} // '.', '.google-auth-perl', 'tokens');
my $port = 0; # Default auto-assign
my $timeout = 300; # Default 5 minutes for human interaction
my $no_browser = 0;
local @ARGV = @args;
GetOptions(
'help|?' => \$help,
'man' => \$man,
'verbose|v' => \$verbose,
'client-id-file=s' => \$client_id_file,
'store-dir=s' => \$store_dir,
'port=i' => \$port,
'timeout=i' => \$timeout,
'no-browser' => \$no_browser,
) or pod2usage(2);
if ($verbose) {
require Log::Any::Adapter;
Log::Any::Adapter->set('Stderr', min_level => 'trace');
}
pod2usage(1) if $help;
pod2usage(-verbose => 2) if $man;
my $command = shift @ARGV;
unless ($command) {
pod2usage(1);
}
if ($command eq 'login') {
do_login(
client_id_file => $client_id_file,
store_dir => $store_dir,
port => $port,
timeout => $timeout,
no_browser => $no_browser,
);
} elsif ($command eq 'application-default') {
my $subcommand = shift @ARGV;
unless ($subcommand) {
die "Error: application-default requires a subcommand (e.g., login)\n";
}
if ($subcommand eq 'login') {
do_adc_login(
client_id_file => $client_id_file,
store_dir => $store_dir,
port => $port,
timeout => $timeout,
no_browser => $no_browser,
);
} else {
die "Unsupported application-default subcommand: $subcommand\n";
}
} elsif ($command eq 'print-access-token') {
do_print_access_token(store_dir => $store_dir,);
} elsif ($command eq 'revoke') {
do_revoke(store_dir => $store_dir,);
} else {
die "Unsupported command: $command\n";
}
}
sub _start_listener {
( run in 1.132 second using v1.01-cache-2.11-cpan-a49fcb8fa48 )