question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect Verified status returned by Firebase Auth Admin SDK Java

See original GitHub issue

[READ] Step 1: Are you in the right place? Yes

[REQUIRED] Step 2: Describe your environment

  • Operating System version: MacOS 10.15.4
  • Firebase SDK version: 6.12.2
  • Library version: (not sure what this is)
  • Firebase Product: auth

[REQUIRED] Step 3: Describe the problem

I’m migrating my application from Google Identity Toolkit to Firebase Auth. During testing I found that for newly registered and verified users, the Firebase Admin SDK for Java returns the email verification status as false even though the user has clicked the link in their email and verified themselves.

The Firebase client for web (Javascript) returns the correct email verification status (true). This is weird because the client sends the idToken to the server. So both are getting the verification status using the same idToken.

I’ve tested this by registering multiple test user accounts and it is reproducible every single time.

This is causing problems because I cannot trust the server to return the correct status. When the user sends a request, the server rejects it saying that user’s email is not verified.

The issue gets resolved if the users logs out and logs in again. Then both client and server return the status as true. But I don’t see a point in forcing the user to log out and log in again.

Relevant Code:

FirebaseToken decodedToken;
try {
	decodedToken = FirebaseAuth.getInstance().verifyIdToken(gtoken);
} catch (FirebaseAuthException e) {			
	e.printStackTrace();
	logger.severe("FirebaseAuthException exception thrown.");
	throw new UnauthorizedException(e);
}

if (decodedToken == null) {
	return null;
}

String emailId = decodedToken.getEmail();
logger.info("Firebase user emailId : " + emailId);

boolean isVerified = decodedToken.isEmailVerified();
logger.info("isVerified : " + isVerified); // prints false

Please let me know if I’m missing something.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hiranya911commented, May 8, 2020

@deepfriedbrain I’m fairly confident such a configuration does not exist at the moment. Ideally you’d need something like a Functions trigger that runs whenever a user account is verified (which sounds like a great feature request for Functions btw). Can you use getIdTokenResult(true) in your client app to side-step this issue?

@bojeil-google do you have any suggestions?

1reaction
deepfriedbraincommented, May 8, 2020

@hiranya911 Thank you for your response. What you said makes sense. I looked up the client code again and it gets the verification status from User object and not the token.

Is there a configuration that could force log out the user from the application the moment their email address was verified? As such, my client won’t know that the user has been verified because the email verification happens completely outside of my application. I knew the API to force refresh the token, but my application won’t know when to force it.

I’m using the default email action handlers. I can look at building custom email handlers later and probably I can have a button that logs the user out. But right now Google Identity Toolkit email / password registration has been disabled and I need to migrate out urgently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Admin Authentication API Errors | Firebase - Google
The Firebase ID token has been revoked. The credential used to initialize the Admin SDK has insufficient permission to access the requested Authentication...
Read more >
Java Firebase Admin SDK verify email error - Stack Overflow
I am building a Rest API with Spring Boot and Firebase Auth using the Admin SDK. I am creating the user in Firebase...
Read more >
Managing users programmatically - Identity Platform
This document shows you how to use the Identity Platform Admin SDK to manage your users programmatically. The Admin SDK allows you to...
Read more >
Build a Role-based API with Firebase Authentication - Toptal
createUser({ displayName, password, email }) await admin.auth().setCustomUserClaims(uid, { role }) return res.status(201).send({ uid }) } catch (err) ...
Read more >
Email Verification in Firebase Auth
To solve this problem, Email Verification has been added to Firebase Auth - where, in the above case, Firebase will send an email...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found