kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
994 stars 163 forks source link

Why i get this error on verifyIdToken method? #83

Closed Minotti closed 3 years ago

Minotti commented 3 years ago

The given token could not be parsed: Error while decoding from Base64Url, invalid base64 characters detected.

I made a test application just to get the idToken of my login in an application made in Flutter.

I copied the token and put it in the Controller just to test it, and I'm having this error.

Am I stupid? Is there a smarter way to test a flutter app with the backend?

Or is it really a mistake?

In Flutter id get token by user.getIdToken()

jeromegamez commented 3 years ago

Without any code and/or examples it's hard for me to guess what might have gone wrong ๐Ÿ˜…. The error states a base64 decode error - could you check if entering the token for example in an online base64 decoder, yields an error or not?

I don't know Firebase for Flutter enough, so I can't confirm nor deny that user.getIdToken() returns a value ready to be transmitted, but if you would share the PHP code you're using to verify the ID token, I can at least confirm if that's looking alright ๐Ÿคž๐Ÿผ

Minotti commented 3 years ago

Well, this is my code, very simplistic, just for testing.

Seleรงรฃo_115

In anyone decoder base64 online I don't get an error.

If I try to give a base64_decode ($idToken) and stop for parseToken or verifyIdToken I get this message:

The given token could not be parsed: The JWT string must have two dots

jeromegamez commented 3 years ago

I'll look into why the verifyIdToken() method doesn't accept the output of parseToken(), because it should.

In the meantime: you shouldn't need both methods, verifyIdToken() also returns the parsed token, sonic you remove the parseToken() call, it should work.

jeromegamez commented 3 years ago

Code as a code block is always better than a screenshot (easier to copy and paste ๐Ÿ˜…).

However, I can't reproduce the error (here's the test I added trying to confirm the issue), but since you now shared the actual error you received, I can tell you that what you are using is a JWT, but not an ID token. ID tokens are always signed and the token you're providing is not (a simple JWT has a header and a payload, separated by one dot; a signed JWT has a header, a payload and a signature, separated by two dots).

jeromegamez commented 3 years ago

You mentioned that you copied the token just to test it. A Google search led me to a comment describing the possible issue that print statements from Flutter could have been truncated(https://github.com/flutter/flutter/issues/31635#issuecomment-502790759) with a possible workaround by using debugPrint() instead of print() (https://stackoverflow.com/a/49156942/284325) or by using a helper method (https://github.com/flutter/flutter/issues/22665#issuecomment-458186456)

Minotti commented 3 years ago

@jeromegamez Sorry for taking too long to answer. I will test it and I will return here.

Minotti commented 3 years ago

@jeromegamez WooooooooooooooooooooooooW

(https://github.com/flutter/flutter/issues/31635) This work perfectly. Thank you so much man, you are awesome!

jeromegamez commented 3 years ago

I'm glad it worked out ๐Ÿ™Œ๐Ÿผ