Fix auth emulator multi-tenant import/export#6217
Conversation
|
any news on this PR? |
|
Any way those of us in Firebase user-land can help to expedite this PR's review/readiness @firebase-ops? Context: My team's doing a Google Cloud Identity Platform integration and we're unable to set up the emulator as needed for our local development environment until multi-tenancy is better supported. Happy to help (if we can)! |
I am embarrassed to admit that I just lost a full 2 days on trial-and-error-based debugging of broken import/export functionality in an inherited local dev setup that involves emulated Firebase auth with multi-tenancy...only to finally stumble upon #5623 and this open PR. Given that this PR has been open for over a year now, would someone on this project at least be merciful enough to document this gap -- at a minimum in the online CLI reference, and ideally also in the help messages for the relevant CLI entrypoints? |
|
Hey folks, apologies for the delay here. I'll try to get some time to work on this PR to resolve the merge conflicts and |
joehan
left a comment
There was a problem hiding this comment.
This LGTM, but I'll go find someone with more auth domain expertise to take another pass. Mind adding a CHANGELOG as well?
|
Thanks for the review, CHANGELOG entry added in a4b9751 |
|
@joehan are we ready to move forward on this? Did the auth folks take a look yet? |
|
It's really sad that a lot of devs are making hacky solutions while this fix lies here for almost two years now. :/ |
|
Hi @joehan, any news on this? |
| projectId: project, | ||
| credential: ADMIN_CREDENTIAL, | ||
| }, | ||
| "admin-app-auth-mutli-tenant", |
There was a problem hiding this comment.
super-nit : multi
Description
Proposed fix for #5623
----- emulator export -----
Proposed fix is to export accounts into different
jsonfiles. For example, a project that has the tenants tenant-1 and tenant-2 would generate:Process for emulator export
account-${tenantId}.jsonOutuput export would look like
----- emulator import -----
Proposed fix is to import accounts from the different
jsonfiles created from export.Replace the endpoint being used from
/identitytoolkit.googleapis.com/v1/projects/${this.projectId}/accounts:batchCreate(projects.accounts.batchCreate) to/identitytoolkit.googleapis.com/v1/projects/${this.projectId}/tenants/${tenantId}/accounts:batchCreate(projects.tenants.accounts.batchCreate). This will allow us to specify which tenant the account should belong to.It looks like the the two APIs are almost the same.
Note: AFAICT when no tenantId is provided for the API projects.tenants.accounts.batchCreate, it will use the default tenant.
https://content-identitytoolkit.googleapis.com/v1/projects/<project_id>/tenants//accounts:batchCreatehttps://content-identitytoolkit.googleapis.com/v1/projects/<project_id>/tenants//accounts:batchCreate{ "kind": "identitytoolkit#DownloadAccountResponse", "users": [ { "localId": "9GB64Wph3kXRkoSMZm3ZPWr01cPF", "createdAt": "1691019099015", "lastLoginAt": "1691019099016", "displayName": "Chicken Chicken", "providerUserInfo": [ { "providerId": "google.com", "rawId": "2698285215994534916150568022884447626235", "displayName": "Chicken Chicken", "email": "chicken.chicken.931@example.com", "screenName": "chicken_chicken" } ], "validSince": "1691019147", "email": "chicken.chicken.931@example.com", "emailVerified": true, "disabled": false } ] }Process for emulator import
jsonfiles in<emulator_export_path>/auth_exportimportFromFile----- auth emulator batchGet endpoint -----
Noticed that the batchGet endpoint was not working as intended when passing the path parameter
tenantId. A GET request to127.0.0.1:9099/identitytoolkit.googleapis.com/v1/projects/${projectId}/accounts:batchGet?tenantId=${tenantId}will always return an object containing users from the default tenant.Reference API: https://cloud.google.com/identity-platform/docs/reference/rest/v1/projects.accounts/batchGet
----- auth emulator only shows default tenants users in the UI -----
As mentioned here, "other tenants than the default using the Google Auth Provider are not being listed in the popup sign-in screen". Cause of this may be because the the link created is
localhost:9099/emulator/auth/handler?<query_string>&tid=<tenant_id>, but the emulator is looking forreq.query.tenantId. So the URL should belocalhost:9099/emulator/auth/handler?<query_string>&tenantId=<tenant_id>.tenantIdvstidProposed solution is to get either
req.query.tenantIdorreq.query.tid.Scenarios Tested
Using the sample web app in https://github.com/aalej/issues-5623.
Sample Commands
firebase emulators:start --export-on-exit=./users --import=./users --project demo-project