-
Notifications
You must be signed in to change notification settings - Fork 1k
[FR] Verifying emulated ID Tokens and creating session cookies only works in the Functions Emulator #2764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm running into this as well. I can't verify |
@favs-sama where are you running the admin code? Right now |
@samtstern originally i'm running the admin code |
@favs-sama yeah right now the only way to test this is inside the Functions emulator. We do want to change this eventually but it requires us to build in a more secure version of So for now I'll consider this a feature request. |
I've created b/172262218 to track this feature request internally |
Also running into this. Will be watching this issue. |
I changed the name of this issue to more accurately reflect the feature request and include the use case from #2770 |
I'd need to verify/decode the token with the emulator as well. |
I was planing to use the auth emulator to do tests without some weird workarounds required at the moment. I think that this behaviour (or at least some imitation of it) should be implemented for testing purposes. This also should have been mentioned at the documentation, would have saved me some time haha |
Does anyone have a workaround for this? |
@samtstern just voicing my support for this - many, many engineers do not use https.callable and instead opt for express setups, myself included. Not being able to support this means that we have a lack of ability to test our client-server interaction through integration tests. From an engineering perspective, shouldn't this be as easy as disabling the 'kid' claim check when a certain envvar is set to true (IE, an envvar that is only set when firebase is running emulator mode)? I don't particularly understand why this would be hard to facilitate. |
@mjgerace we know how to do this, but we're being extra careful about security. If your production server ever got into a situation where it thought it should disable/skip ID token verification then you'd have a big problem! In order to have something in time for the launch of the Auth Emulator we compromised on a simple solution in the Node.js Admin SDK that is only enabled inside the Functions emulator. We are actively working on a longer-term solution that we're happier with and when we finish it we will bring it to all of our Admin SDKs (Node, Java, Go, Python, etc) so that you can develop on your own server. |
@samtstern this makes total sense - is there any timeline for this work? In the meantime, would it be bad for our team to set an env var (FIREBASE_EMULATOR=1 yarn jest {test_file}) and otherwise workaround the issue in my actual auth middleware? So long as I can modify the |
@mjgerace we never offer timelines but this is something we're actively working on, it's not on the backlog. If you want to work around this issue on your own server and you're confident you know how, go for it! |
At the moment when I'm running tests i change NODE_ENV environment variable to "test" and, based on that, change the auth token checking code to use the decode function from 'jsonwebtoken' module instead of firebase auth |
@samtstern Couldn't this be as simple as checking for the presence of the |
@nicoburns we use the presence of that environment variable to redirect any outbound HTTP requests the Admin SDK makes to the Auth API. However verifying ID Tokens and creating session cookies are mostly local operations that do not touch the Auth API. So changing how they work just based on the presence of an env var would create the possibility of someone remotely short-circuiting your Admin server's security, something we really really want to avoid. We're working on changes to how the Admin SDK handles these operations that will make it safer to fix this issue. |
any updates on this? |
The error seems to also happen despite using the Functions emulator - do you mean that it only works if |
@athomasoriginal firebase/firebase-admin-java#493 tracks the Java Admin SDK feature request. |
@yuchenshi Let's update the Firebase documentation. It still says
ref: https://firebase.google.com/docs/emulator-suite/connect_auth#id_tokens |
@vajahath We're updated the docs. Thanks for the heads up. |
Hi. A silly question perhaps, but where does one set the FIREBASE_AUTH_EMULATOR_HOST environment variable? The documentation doesn't explicitly state it. In which file should it be set? Where should it be located? @Joebayld , you seem to have figured it out, so any advice would be really appreciated... :) Thanks! |
It's environment variable, you can set it globally in ~/.bash_profile or in terminal before firebase command: For convenience use something like https://www.npmjs.com/package/dotenv, to separate configurations. |
Thanks @v-kiniv . Only I made it work by setting the variable on the dev script as opposed to the emulators script:
|
This still existing in my case ,
i am using firebase latest : const idToken="eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJlbWFpbCI6InJvaGFuLmtoYWFuYWlvQGdtYWlsLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiYXV0aF90aW1lIjoxNjI3NTY5NDA3LCJ1c2VyX2lkIjoiQ2VmQXV6ZlFsdG4yWkN2V1dIYU9rWE82YmhOMCIsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsicm9oYW4ua2hhYW5haW9AZ21haWwuY29tIl19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifSwiaWF0IjoxNjI3NTY5NDA3LCJleHAiOjE2Mjc1NzMwMDcsImF1ZCI6InNreWNybS0xYjYzOSIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9za3ljcm0tMWI2MzkiLCJzdWIiOiJDZWZBdXpmUWx0bjJaQ3ZXV0hhT2tYTzZiaE4wIn0.";
admin.auth().verifyIdToken(idToken).then((decodedToken) => {
console.log("decode token", decodedToken);
}) |
Make sure you've updated |
sorry ! it was my Bad , after set env. reload the console can help if some one else stuck in same situation. 😀😀 |
Any news on this for other SDKs? I'm developing with Go and came across this. Not hard to bypass when you find this but takes an hour to figure out why and implement it EDIT. Seems my problem was using old package. Firestore docs https://firebase.google.com/docs/firestore/quickstart#go tell to install the old GOPATH version and not /v4 |
Everyone Having issue make sure by using : |
Oh my! You're a life saver! Following the docs does lead go users right into this issue. Thanks for this. And thanks firebase team! |
Is there an implementation (or merge) reference of the type of branching |
This is still happening to me. I am logging the user in using the following piece of code in Swift: Auth.auth().signIn(withEmail: email, password: password) I am then passing in an ID token to the backend web call like so:
Finally, I am using Express/Cloud Run on the backend and verifying my token like this:
However, I am getting the following error message: FirebaseAuthError: Firebase ID token has no "kid" claim. See https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve an ID token. When I go to that URL, it tells me to do exactly what Im doing, so what am I doing wrong? |
@jalvini If you are having issues, can you file a new bug? |
Even with the env var Im getting this error:
|
* FIX: Error: Firebase ID token has no kid claim. firebase/firebase-tools#2764 * FEAT: add cors support for /token endpoint * FEAT: add cors support, response_type and redirect param to /consent endpoint * FIX: post /consent does not send response * FEAT: /authentication add supprot to custom consent url * FIX: post /consent was missing await * FEAT: post/ authorize/conset pass redirect_uri, query and fragments as well * add .npmrc to .gitignore * 0.3.0 * REVERT: add .npmrc to .gitignore * FEAT: validateScope -> support multiple comman separated scopes * 0.3.1 * FEAT: createOrUpdateAccessToken -> Create firebase custom token for custom auth and set scopes as claims for security rules * 0.3.2 * FEAT: createOrUpdateAccessToken -> pass authId as custom claim to access it when removing access * 0.3.3 * FIX: always split/join scope by space * 0.3.4 * FEAT: support passing scope separator string via configuration * 0.3.5 * RFR: save custom token calim scopes as string as firebase database rules do not support arrays * 0.3.6 * FEAT: add new claim to custom token to id oauth is used * 0.3.7 * FEAT: authentication -> add support for redirect param * FEAT: add support for multiple redirect uris * CHORE: update package.json to @neurosity/oauth2-firebase-auth * 0.4.0 * FIX: allow redirect uris to have any path, enforce host and protocol * 0.4.1 * FEAT: functions now support runtime options via runWith argument option * 0.5.0 * ADD: prepublish script * 0.5.1 * ADD: clean scrips * 0.5.2
* FIX: Error: Firebase ID token has no kid claim. firebase/firebase-tools#2764 * FEAT: add cors support for /token endpoint * FEAT: add cors support, response_type and redirect param to /consent endpoint * FIX: post /consent does not send response * FEAT: /authentication add supprot to custom consent url * FIX: post /consent was missing await * FEAT: post/ authorize/conset pass redirect_uri, query and fragments as well * add .npmrc to .gitignore * 0.3.0 * REVERT: add .npmrc to .gitignore * FEAT: validateScope -> support multiple comman separated scopes * 0.3.1 * FEAT: createOrUpdateAccessToken -> Create firebase custom token for custom auth and set scopes as claims for security rules * 0.3.2 * FEAT: createOrUpdateAccessToken -> pass authId as custom claim to access it when removing access * 0.3.3 * FIX: always split/join scope by space * 0.3.4 * FEAT: support passing scope separator string via configuration * 0.3.5 * RFR: save custom token calim scopes as string as firebase database rules do not support arrays * 0.3.6 * FEAT: add new claim to custom token to id oauth is used * 0.3.7 * FEAT: authentication -> add support for redirect param * FEAT: add support for multiple redirect uris * CHORE: update package.json to @neurosity/oauth2-firebase-auth * 0.4.0 * FIX: allow redirect uris to have any path, enforce host and protocol * 0.4.1 * FEAT: functions now support runtime options via runWith argument option * 0.5.0 * ADD: prepublish script * 0.5.1 * ADD: clean scrips * 0.5.2
* FIX: Error: Firebase ID token has no kid claim. firebase/firebase-tools#2764 * FEAT: add cors support for /token endpoint * FEAT: add cors support, response_type and redirect param to /consent endpoint * FIX: post /consent does not send response * FEAT: /authentication add supprot to custom consent url * FIX: post /consent was missing await * FEAT: post/ authorize/conset pass redirect_uri, query and fragments as well * add .npmrc to .gitignore * 0.3.0 * REVERT: add .npmrc to .gitignore * FEAT: validateScope -> support multiple comman separated scopes * 0.3.1 * FEAT: createOrUpdateAccessToken -> Create firebase custom token for custom auth and set scopes as claims for security rules * 0.3.2 * FEAT: createOrUpdateAccessToken -> pass authId as custom claim to access it when removing access * 0.3.3 * FIX: always split/join scope by space * 0.3.4 * FEAT: support passing scope separator string via configuration * 0.3.5 * RFR: save custom token calim scopes as string as firebase database rules do not support arrays * 0.3.6 * FEAT: add new claim to custom token to id oauth is used * 0.3.7 * FEAT: authentication -> add support for redirect param * FEAT: add support for multiple redirect uris * CHORE: update package.json to @neurosity/oauth2-firebase-auth * 0.4.0 * FIX: allow redirect uris to have any path, enforce host and protocol * 0.4.1 * FEAT: functions now support runtime options via runWith argument option * 0.5.0 * ADD: prepublish script * 0.5.1 * ADD: clean scrips * 0.5.2
* FIX: Error: Firebase ID token has no kid claim. firebase/firebase-tools#2764 * FEAT: add cors support for /token endpoint * FEAT: add cors support, response_type and redirect param to /consent endpoint * FIX: post /consent does not send response * FEAT: /authentication add supprot to custom consent url * FIX: post /consent was missing await * FEAT: post/ authorize/conset pass redirect_uri, query and fragments as well * add .npmrc to .gitignore * 0.3.0 * REVERT: add .npmrc to .gitignore * FEAT: validateScope -> support multiple comman separated scopes * 0.3.1 * FEAT: createOrUpdateAccessToken -> Create firebase custom token for custom auth and set scopes as claims for security rules * 0.3.2 * FEAT: createOrUpdateAccessToken -> pass authId as custom claim to access it when removing access * 0.3.3 * FIX: always split/join scope by space * 0.3.4 * FEAT: support passing scope separator string via configuration * 0.3.5 * RFR: save custom token calim scopes as string as firebase database rules do not support arrays * 0.3.6 * FEAT: add new claim to custom token to id oauth is used * 0.3.7 * FEAT: authentication -> add support for redirect param * FEAT: add support for multiple redirect uris * CHORE: update package.json to @neurosity/oauth2-firebase-auth * 0.4.0 * FIX: allow redirect uris to have any path, enforce host and protocol * 0.4.1 * FEAT: functions now support runtime options via runWith argument option * 0.5.0 * ADD: prepublish script * 0.5.1 * ADD: clean scrips * 0.5.2
I had to change mine to
|
any update on this for the go v4 sdk? is it safe to use "firebase.google.com/go" instead of v4? |
I implemented like this:
|
For those still facing the issue I found that the problem for me was not using "" for the variable FIREBASE_AUTH_EMULATOR_HOST="localhost:9099" instead of FIREBASE_AUTH_EMULATOR_HOST=localhost:9099 |
Unreal that I am still getting the "Firebase ID token has no "kid" claim". Complete joke. |
[REQUIRED] Environment info
firebase-tools: 8.14.1
Platform: Windows 10
[REQUIRED] Test case
Currently emulating a scenario where a signed in user sends userToken from frontend and backend decoded this token and retrieves uid for fetching data from database.
[REQUIRED] Steps to reproduce
make sure that the following node packages are installed and firebase emulators for auth, firestore, and database are enabled:
[REQUIRED] Expected behavior
The userToken is decoded properly so that uid is extracted from the token for fetching data.
[REQUIRED] Actual behavior
It fails with Firebase ID token has no "kid" claim. The code is working normally except when using emulator.
The text was updated successfully, but these errors were encountered: