EMDIS-ECS
view release on metacpan or search on metacpan
script/ecs_token view on Meta::CPAN
console, select I<Navigation menu> > I<APIs & Services> >
I<OAuth consent screen>. On the I<OAuth Overview> page, click the
I<Get started> button. On the I<Project configuration> page, under
I<App Information> enter the I<App name> and I<User support email>, and
click the I<Next> button. Under I<Audience> select I<External> and click
the I<Next> button. Under I<Contact information> enter I<Email addresses>
and click the I<Next> button. Under I<Finish> click the I<I agree ...>
checkbox and click the I<Continue> button. Then, click the I<Create>
button.
=item 5.
Create OAuth 2.0 client ID for Perl ECS app. In I<Google Cloud> console,
select I<Navigation menu> > I<APIs & Services> > I<Credentials>. On the
I<Credentials> page, click the I<+ Create credentials> button and select
I<OAuth client ID> from the drop-down menu. On the I<Create OAuth client ID>
page select I<Web application> as the I<Application type> and enter an
appropriate name for the app (e.g. "Perl ECS"). Under
I<Authorized redirect URIs> click the I<+ Add URI> button and enter the
following URI (as mentioned in the C<oauth.py> script):
https://google.github.io/gmail-oauth2-tools/html/oauth2.dance.html
Then, click the I<Create> button.
From the I<OAuth client created> popup, make note of the I<Client ID> and
I<Client secret>. Click I<OK>.
=item 6.
Allow a few minutes for the settings to take effect.
=back
=item 4.
Add the email account as a test user for the project. In I<Google Cloud>
console, select I<Navigation menu> > I<APIs & Services> >
I<OAuth consent screen>, then select I<Audience>. On the I<Audience>
page, under I<Test users> click the I<+ Add users> button. In the
I<Add users> panel enter the test user's email address (e.g. xyz@gmail.com)
and click the I<Save> button.
=item 5.
Use C<oauth2.py> script to generate and authorize an OAuth 2 token. See also
comments in script. E.g.:
python3 oauth2.py --user=xyz@gmail.com \
--client_id=1038[...].apps.googleusercontent.com \
--client_secret=VWFn8LIKAMC-MsjBMhJeOplZ \
--generate_oauth2_token
To authorize the token, use a web browser to visit the URL indicated by the
script and follow the browser-based authorization flow. At the script's
C<Enter verification code> prompt, enter the authorization code displayed in
the web browser. If successful, the script displays a C<Refresh Token> and
C<Access Token>.
If the browser authorization flow results in an error saying "Access
blocked: google.github.io has not completed the Google verification process",
add the email account as a test user for the project (see above) and reload
the URL provided by the C<oauth2.py> script.
=item 6.
Use C<oauth2.py> script to test SMTP authentication. E.g.:
python3 oauth2.py --user=xxx@gmail.com \
--access_token=ya29.a0A[...]0175 \
--test_smtp_authentication
=item 7.
Use C<oauth2.py> script to test IMAP authentication. E.g.:
python3 oauth2.py --user=xxx@gmail.com \
--access_token=ya29.a0A[...]0175 \
--test_imap_authentication
=item 8.
Use C<oauth2.py> script to obtain a new access token, using a refresh token.
E.g.:
python3 oauth2.py \
--client_id=1038[...].apps.googleusercontent.com \
--client_secret=VWFn8LIKAMC-MsjBMhJeOplZ \
--refresh_token=1//04[...]anrA
=back
=head1 RETURN VALUE
Returns a non-zero exit code if an error is encountered.
=head1 SEE ALSO
EMDIS::ECS::Config, https://gnupg.org/, https://www.passwordstore.org/,
https://developers.google.com/workspace/gmail/imap/xoauth2-protocol,
https://datatracker.ietf.org/doc/html/rfc7628,
https://datatracker.ietf.org/doc/html/rfc6749,
https://oauth.net/2/
=head1 AUTHOR
Joel Schneider <jschneid@nmdp.org>
=head1 COPYRIGHT AND LICENSE
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Copyright (C) 2025-2026 National Marrow Donor Program. All rights reserved.
See LICENSE file for license details.
=head1 HISTORY
ECS, the EMDIS Communication System, was originally designed and implemented
( run in 0.648 second using v1.01-cache-2.11-cpan-ceb78f64989 )