FusionAuth / fusionauth-typescript-client

A TypeScript client for FusionAuth
https://fusionauth.io
Apache License 2.0
60 stars 27 forks source link

retrieveUserByX does not allow specification of a tenant id #77

Closed theogravity closed 1 year ago

theogravity commented 1 year ago

The following methods do not allow the specification of a tenant id, which is problematic when you have multiple tenants:

X-FusionAuth-TenantId [String] OPTIONAL
The unique Id of the tenant used to scope this API request.

When only a single tenant is configured the tenant Id can be assumed and this additional header is optional. Once more than one tenant has been configured in FusionAuth the tenant Id is required for this request because the input parameters by themselves do not indicate which tenant the request is intended.

The tenant Id may be provided through this header or by using a tenant locked API key to achieve the same result.
mooreds commented 1 year ago

You should be able to add the tenantId via the setTenantId method: https://github.com/FusionAuth/fusionauth-typescript-client/blob/master/src/FusionAuthClient.ts#L40

Have you tried that and found it didn't work?

theogravity commented 1 year ago

You should be able to add the tenantId via the setTenantId method: https://github.com/FusionAuth/fusionauth-typescript-client/blob/master/src/FusionAuthClient.ts#L40

Have you tried that and found it didn't work?

I was not aware of this method, thanks.

I only run a single instance of the client, I'm guessing setTenantId would affect all calls once set? If I had separate tenant ids during individual requests, would I then have to create a context/request-specific client then?

mooreds commented 1 year ago

I'm guessing setTenantId would affect all calls once set? If I had separate tenant ids during individual requests, would I then have to create a context/request-specific client then?

You are correct. If you have multiple tenants, you'll want to create multiple clients and call setTenantId on each of them appropriately.

mooreds commented 1 year ago

Please close this issue if the workaround is acceptable.

theogravity commented 1 year ago

Thanks!