Skip to content
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

request.auth is null for what should be a valid request with self-made custom token [Firestore emulation] #4795

Closed
akauppi opened this issue Apr 15, 2021 · 7 comments · Fixed by #4810

Comments

@akauppi
Copy link

akauppi commented Apr 15, 2021

[REQUIRED] Describe your environment

  • Operating System version: macOS 11.2.3
  • Browser version: Chrome 89
  • Firebase SDK version: 9.0.0-beta.1
  • Firebase Product: firestore

[REQUIRED] Describe the problem

The context is emulation (development). In production everything is nice.

In my security rules, request.auth is null though it should not.

I've authenticated in web client like this:

        await signInWithCustomToken( auth, JSON.stringify({ uid }) )
          .then( creds => {
            console.debug("Signed in as:", { creds });
          })
          .catch( err => {
            console.error("Sign-in failed:", err);
          });

I can see in the browser console that the sign-in is successful.

firestore-debug.log shows this warning:

Apr 15, 2021 1:19:05 PM com.google.net.webchannel.server.common.CorsFilter populateCustomHeaders
WARNING: Invalid $httpHeaders: X-Goog-Api-Client:gl-js/ fire/8.4.1
X-Firebase-GMPID:
Content-Type:text/plain
Authorization:Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJuYW1lIjoiSnVzdCBNZSIsInBpY3R1cmUiOiJodHRwczovL25vLnN1Y2guZG9tYWluIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJhdXRoX3RpbWUiOjE2MTg0ODE5NDUsInVzZXJfaWQiOiJkZXYiLCJmaXJlYmFzZSI6eyJpZGVudGl0aWVzIjp7fSwic2lnbl9pbl9wcm92aWRlciI6ImN1c3RvbSJ9LCJpYXQiOjE2MTg0ODE5NDUsImV4cCI6MTYxODQ4NTU0NSwiYXVkIjoiYXBwIiwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL2FwcCIsInN1YiI6ImRldiJ9.

Can I do something about that?

But the real problem is that I cannot subscribe to changes of the connection guarded by a rule that uses request.auth.uid. I've established that request.auth is null, by playing with the rule.

Steps to reproduce:

$ git clone [email protected]:akauppi/GroundLevel-firebase-es.git
$ cd GroundLevel-firebase-es
$ git checkout interim   # this branch
$ npm install
$ cd packages/app
$ npm install
$ npm run dev

Open http://localhost:3000/?user=dev and observe the contents of the firestore-debug.log

Expected:

jolly-is-missing

Actual:

As above, without the project entry.

This looks like a bug or two, to me. Things used to work long ago. The current code is based on 9.0.0-beta.1 and I'm no longer able to try with 8.x APIs. Not sure which change has started this problem.

Thanks for any help!

@ANDREYDEN
Copy link

@akauppi Something similar happened to me yesterday. I have downgraded to firebase: 8.3.0 and the issue was gone (make sure to clean up package-lock.json and node_modules). Seems like 8.4.0 also has the same issue.

@akauppi
Copy link
Author

akauppi commented Apr 16, 2021

@ANDREYDEN Thanks for the extra info. In my case, I’m (happily) stuck with the 9.x beta (different API) so no downgrade possibility, but I trust Firebase to look into this, and suggest a fix.

@samtstern
Copy link
Contributor

@akauppi what version of the Firebase CLI are you using? v9.9.0 includes a critical bug fix around parsing auth headers:
https://github.com/firebase/firebase-tools/releases/tag/v9.9.0

@akauppi
Copy link
Author

akauppi commented Apr 17, 2021

@samtstern I'm using the latest, 9.10.0 so it's not that.

@Davste93
Copy link

Was this closed because it was fixed? I'm running 9.10.2 and I have the same issue.

@akauppi
Copy link
Author

akauppi commented May 14, 2021

@Davste93 I received the fix with some update. Are you on firebase-tools 9.10.2 that has Firestore emulator 1.11.15?

@nocteryals
Copy link

nocteryals commented May 21, 2021

Hi!
First, I want to say thanks! you saved me, i had been looking for two days how to solve it.
I work with IONIC 5 and Capacitor. I leave me package.json to whoever may be interested.

This bug is happen to a lot of people but is very difficult find the reason and this forum.

again, thanks a lot to all!

{
"name": "test_notifications",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"start": "ionic-app-scripts serve",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint"
},
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "^5.2.11",
"@angular/compiler": "^5.x.x",
"@angular/compiler-cli": "^5.x.x",
"@angular/core": "^5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "^5.2.11",
"@angular/platform-browser-dynamic": "^5.x.x",
"@ionic-native/badge": "^4.20.0",
"@ionic-native/core": "~4.20.0",
"@ionic-native/crop": "^4.20.0",
"@ionic-native/device": "^4.20.0",
"@ionic-native/diagnostic": "^4.20.0",
"@ionic-native/email-composer": "^4.20.0",
"@ionic-native/file": "^4.20.0",
"@ionic-native/file-chooser": "^4.20.0",
"@ionic-native/file-path": "^4.20.0",
"@ionic-native/firebase": "^4.20.0",
"@ionic-native/geolocation": "^4.20.0",
"@ionic-native/image-picker": "^4.20.0",
"@ionic-native/keyboard": "^4.20.0",
"@ionic-native/open-native-settings": "^4.20.0",
"@ionic-native/splash-screen": "~4.20.0",
"@ionic-native/status-bar": "~4.20.0",
"@ionic/storage": "2.2.0",
"@ng-bootstrap/ng-bootstrap": "^5.2.2",
"@types/node": "^8.10.58",
"angularfire2": "^5.2.3",
"cordova-android": "^8.1.0",
"cordova-ios": "^5.1.1",
"cordova-plugin-androidx": "^2.0.0",
"cordova-plugin-androidx-adapter": "^1.1.1",
"cordova-plugin-crop": "0.4.0",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-email-composer": "^0.9.2",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-filechooser": "^1.2.0",
"cordova-plugin-filepath": "^1.5.8",
"cordova-plugin-firebasex": "^9.1.1",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-telerik-imagepicker": "^2.3.3",
"cordova-plugin-update": "^0.1.0",
"cordova.plugins.diagnostic": "^6.0.2",
"firebase": "^7.24.0",
"image-compressor": "^2.0.3",
"ionic-angular": "3.9.5",
"ionic-img-viewer": "^2.9.0",
"ionicons": "3.0.0",
"ios-deploy": "^1.11.3",
"ng-lazyload-image": "^9.0.1",
"ngx-skeleton-loader": "^2.5.0",
"promise-polyfill": "^8.1.3",
"rxjs": "^6.0.0",
"rxjs-compat": "^6.0.0",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.29"
},
"devDependencies": {
"@ionic/app-scripts": "3.2.2",
"cordova-open-native-settings": "^1.5.2",
"cordova-plugin-badge": "^0.8.8",
"cordova-plugin-geolocation": "^4.0.2",
"cordova-plugin-ionic-webview": "^2.5.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"typescript": "^3.7.2",
"xcode": "^2.1.0"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-filepath": {},
"cordova-plugin-telerik-imagepicker": {
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "Utilizaremos tus fotografias cuando quieras cambiar tu perfil y compartir tus fotos con los demás"
},
"cordova-plugin-device": {},
"cordova-plugin-email-composer": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
},
"cordova-plugin-file": {},
"cordova-plugin-filechooser": {},
"cordova-plugin-crop": {},
"cordova-plugin-firebasex": {
"FIREBASE_ANALYTICS_COLLECTION_ENABLED": "true",
"FIREBASE_PERFORMANCE_COLLECTION_ENABLED": "true",
"FIREBASE_CRASHLYTICS_COLLECTION_ENABLED": "true",
"ANDROID_ICON_ACCENT": "#FF00FFFF",
"ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION": "17.0.0",
"ANDROID_PLAY_SERVICES_AUTH_VERSION": "18.0.0",
"ANDROID_FIREBASE_ANALYTICS_VERSION": "17.4.0",
"ANDROID_FIREBASE_MESSAGING_VERSION": "20.1.6",
"ANDROID_FIREBASE_CONFIG_VERSION": "19.1.4",
"ANDROID_FIREBASE_PERF_VERSION": "19.0.7",
"ANDROID_FIREBASE_AUTH_VERSION": "19.3.1",
"ANDROID_FIREBASE_INAPPMESSAGING_VERSION": "19.0.6",
"ANDROID_FIREBASE_FIRESTORE_VERSION": "21.4.3",
"ANDROID_CRASHLYTICS_VERSION": "2.10.1",
"ANDROID_CRASHLYTICS_NDK_VERSION": "2.1.1",
"ANDROID_GSON_VERSION": "2.8.6"
},
"cordova.plugins.diagnostic": {
"ANDROIDX_VERSION": "1.+"
},
"cordova-plugin-ionic-webview": {
"ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
},
"cordova-plugin-geolocation": {},
"cordova-open-native-settings": {},
"cordova-plugin-badge": {}
},
"platforms": [
"ios",
"android"
]
}
}

@firebase firebase locked and limited conversation to collaborators May 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants