Failed to login. Message: Failed to exchange authorization code for tokens https://oauth2.googleapis.com/token failed, reason
What happened?
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:
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.
The issue is resolved now, I can login into google now. It must have been something to do with Gemini Backend.
I am getting the issue again as of 1:58 pm Wednesday, 10 September 2025 (UTC)
Same issue here.
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
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.
use VPN
that's weird, it worked for me on vpn
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 │
I came up with same problem, and yes it's because china's firewall, use vpn and tun mode would fix it
Same issue here too
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.
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
I'm in the same boat, totally unable to authenticate.
@nojjynb I just installed package 0.21.2 and it seems to work. Maybe there was a fix?
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 │
│ │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
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.