gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Failed to login. Message: Failed to exchange authorization code for tokens https://oauth2.googleapis.com/token failed, reason

Open shabahmd opened this issue 1 year ago • 16 comments

What happened?

Image Image

What did you expect to happen?

I can not login gemini because im not being authorized in version 4.0.0. I am not sure if its because of version or something else. I even tried adding up my gemini api key in .env in .gemini folder in ubuntu but nothing happened.

Client information

Client Information

Run gemini to enter the interactive CLI, then run the /about command.

> /about
# paste output here

Login information

Google Account Gemini API Key

Anything else we need to know?

gemini- about output is following: gemini /about

Code Assist login required. Attempting to open authentication page in your browser. Otherwise navigate to:

https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=http%3A%2F%2Flocalhost%3A33735%2Foauth2callback&access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&state=ce8fe7f0875a56447a1fcc4b8030652b62ef174b219167ac0cd900b10e39f079&response_type=code&client_id=681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com

Waiting for authentication... Failed to exchange authorization code for tokens: request to https://oauth2.googleapis.com/token failed, reason:

shabahmd avatar Sep 10 '25 11:09 shabahmd

The issue describes a failure in the login process, which points to a bug within the authentication area. Crucial information from the /about command is missing, which is necessary for further diagnosis. Due to the critical nature of login functionality, this issue may be a high priority, but without priority labels available for assignment, this cannot be set.

gemini-cli[bot] avatar Sep 10 '25 11:09 gemini-cli[bot]

The issue is resolved now, I can login into google now. It must have been something to do with Gemini Backend.

shabahmd avatar Sep 10 '25 12:09 shabahmd

I am getting the issue again as of 1:58 pm Wednesday, 10 September 2025 (UTC)

shabahmd avatar Sep 10 '25 13:09 shabahmd

Same issue here.

bilal-alam-ef avatar Sep 11 '25 13:09 bilal-alam-ef

If you live in Pakistan, use VPN because PTA is implementing Chinese Firewall in Pakistan.; I use vpn and I set up gemini api in project directory so it automatically authenticates. This solved for me.

@bilal-alam-ef

shabahmd avatar Sep 12 '25 00:09 shabahmd

Some confusion here, are you talking about setting gemini api key from AI Studio in Google Cloud Project? @shabahmd . Please elaborate and yes i live in Pakistan.

bilal-alam-ef avatar Sep 12 '25 05:09 bilal-alam-ef

use VPN

that's weird, it worked for me on vpn

mrxehmad avatar Sep 22 '25 16:09 mrxehmad

installed gemini-cli via homebrew; starting it it presents three options - selecting "authenticate via google.com" ends exactly in the same error

if I generate Google API Key then i'm at least able to start a new session - otherwise the only way to exit is to kill the terminal (seems pretty much UI bug, besides others, can still cycle through the 3 options - but nothing else)

╭──────────────────────────────────────────────────────────────────────────────────╮
│                                                                                  │
│ About Gemini CLI                                                                 │
│                                                                                  │
│ CLI Version                 0.5.4                                                │
│ Git Commit                  f3cb841e                                             │
│ Model                       gemini-2.5-pro                                       │
│ Sandbox                     no sandbox                                           │
│ OS                          darwin                                               │
│ Auth Method                 gemini-api-key                                       │
│                                                                                  │
╰──────────────────────────────────────────────────────────────────────────────────╯

in the "dead" terminal: │ Failed to login. Message: Failed to exchange authorization code for tokens: request to https://oauth2.googleapis.com/token failed, reason: unable to get local issuer certificate │

romanchyla avatar Sep 25 '25 01:09 romanchyla

I came up with same problem, and yes it's because china's firewall, use vpn and tun mode would fix it

world-better avatar Nov 05 '25 04:11 world-better

Same issue here too

DCT-Berinyuy avatar Dec 15 '25 06:12 DCT-Berinyuy

If you have ever created projects or api keys in (https://aistudio.google.com/), please delete them and try again, this may solve your problem, it did for me.

easonJZ avatar Dec 15 '25 09:12 easonJZ

I've run into this issue several times and it's consistently failing sign in now.

I've tried enrolling a workspace account and non-workspace account into the Google Developer Program and sign in but it fails.

Historically, the CLI was working fine. And now I've authed with VS Code onto the personal account but the same personal account fails to auth with CLI...

With VPN and without VPN, I am unable to authenticate the CLI

aquaflamingo avatar Dec 17 '25 21:12 aquaflamingo

I'm in the same boat, totally unable to authenticate.

nojjynb avatar Dec 17 '25 22:12 nojjynb

@nojjynb I just installed package 0.21.2 and it seems to work. Maybe there was a fix?

aquaflamingo avatar Dec 18 '25 01:12 aquaflamingo

It still fails:

Code Assist login required. Opening authentication page in your browser. Do you want to continue? [Y/n]: 

 ███            █████████  ██████████ ██████   ██████ █████ ██████   █████ █████
░░░███         ███░░░░░███░░███░░░░░█░░██████ ██████ ░░███ ░░██████ ░░███ ░░███
  ░░░███      ███     ░░░  ░███  █ ░  ░███░█████░███  ░███  ░███░███ ░███  ░███
    ░░░███   ░███          ░██████    ░███░░███ ░███  ░███  ░███░░███░███  ░███
     ███░    ░███    █████ ░███░░█    ░███ ░░░  ░███  ░███  ░███ ░░██████  ░███
   ███░      ░░███  ░░███  ░███ ░   █ ░███      ░███  ░███  ░███  ░░█████  ░███
 ███░         ░░█████████  ██████████ █████     █████ █████ █████  ░░█████ █████
░░░            ░░░░░░░░░  ░░░░░░░░░░ ░░░░░     ░░░░░ ░░░░░ ░░░░░    ░░░░░ ░░░░░

                                              v0.29.0-nightly.20260205.a3af4a8ca
Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                                                         │
│ ? Get started                                                                                                                                                                                                                           │
│                                                                                                                                                                                                                                         │
│   How would you like to authenticate for this project?                                                                                                                                                                                  │
│                                                                                                                                                                                                                                         │
│   ● 1. Login with Google                                                                                                                                                                                                                │
│     2. Use Gemini API Key                                                                                                                                                                                                               │
│     3. Vertex AI                                                                                                                                                                                                                        │
│                                                                                                                                                                                                                                         │
│   Failed to login. Message: Failed to exchange authorization code for tokens: request to https://oauth2.googleapis.com/token failed, reason: unable to get local issuer certificate                                                     │
│                                                                                                                                                                                                                                         │
│   (Use Enter to select)                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                                         │
│   Terms of Services and Privacy Notice for Gemini CLI                                                                                                                                                                                   │
│                                                                                                                                                                                                                                         │
│   https://github.com/google-gemini/gemini-cli/blob/main/docs/tos-privacy.md                                                                                                                                                             │
│                                                                                                                                                                                                                                         │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

simonbcn avatar Feb 06 '26 13:02 simonbcn

If you have ever created projects or api keys in (https://aistudio.google.com/), please delete them and try again, this may solve your problem, it did for me.

This is the solution that worked for me today after trying all the official troubleshooting steps and seeing no results.

meghanto avatar Mar 20 '26 00:03 meghanto