-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Cesium.ITwinPlatform.defaultAccessToken should be a function instead of a string #12386
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
@jjspace Could you please triage? |
Some initial thoughts on a plan Our The question would just be how best to expose this in the API. I'm currently thinking of adding a function Then in each internal const resource = new Resource({
// ...
retryCallback: async function (resource, error) {
if (error.statusCode !== 403) {
// we only care about Auth failures
return false;
}
const newToken = await ITwinPlatform.requestNewAuthToken();
if (!defined(newToken)) {
return false;
}
resource.headers.Authorization = `Bearer ${newToken}`;
ITwinPlatform.defaultAccessToken = newToken;
return true;
},
retryAttempts: 1,
}); The resulting code for users of this API would look something like this const authToken = await requestAuthToken();
ITwinPlatform.defaultAccessToken = authToken;
ITwinPlatform.requestNewAuthToken = requestAuthToken();
ITwinData.createTilesetFromIModelId(iModelId); There's a larger discussion to be had about how Right now the token needs to be stored "somewhere else" which is the |
I thought about this a little more recently and I don't actually think the solution I proposed above will work. Replacing/augmenting the |
Feature
Propose that
Cesium.ITwinPlatform.defaultAccessToken
be converted toCesium.ITwinPlatform.getDefaultAccessToken
as an async function instead of a stringThe main justification of this change is to avoid dealing with that token expiring.
As a static string, unless the user resets it, the token will expire and if they set it to a variable the reference will be lost and again it will expire.
As an async function it always grabs the latest token. The consumer is forced to call it before they use it, but as tokens are always used for async requests to a service, this should not be a problem. Additionally, if they do save it on a variable the result is still a valid token. Effectively, you are free from this expiration contingency now.
References:
iModel integration
The text was updated successfully, but these errors were encountered: