itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

`CloudSqlite.requestToken` returns empty token if `BlobContainer.service` is not defined

Open johnnyd710 opened this issue 11 months ago • 0 comments

If BlobContainer.service is undefined, any call to CloudSqlite.requestToken will return "" which is usually interpreted as a sign-in error (see IModelApp.getAccessToken). So its impossible to tell the difference between an authentication error (e.g., user does not have RBAC permissions for the cloud sqlite container) and BlobContainer.service not being set. I believe the problematic line is here:

// `@itwin/core-backend` CloudSqlite.ts
  export async function requestToken(args: RequestTokenArgs): Promise<AccessToken> {
    // allow the userToken to be supplied via Rpc. If not supplied, or blank, use the backend's accessToken.
    const userToken = args.userToken ? args.userToken : (await IModelHost.getAccessToken());
    const response = await BlobContainer.service?.requestToken({ ...args, userToken });
    return response?.token ?? "";
  }

Expected behavior

I would expect if BlobContainer.service is undefined, I'd get a clear error message BlobContainer.service is not defined or something like that so I know I forgot to initialize it.

johnnyd710 avatar Mar 14 '24 13:03 johnnyd710