so in our APP we use a Portal login for Authentification, I add the used Code below. I noticed that when creating a new FeatureLayer a Request to /server/rest/services/03/xx/FeatureServer/2?f=json gets sent with response {"error":{"code":499,"message":"Token Required","details":[]}}, it automatically resends that request with token than it works. I'd like to savemyself all these requests and include the token on start.
before FeatureLayer Creation.
I added the token via the customParameter property while creating the featureLayer.
What seemed to work at first, was setting the token in the apiKey property while initializing the FeatureLayer, however after the token had to be refreshed, the client didn't change to the new token.
private readonly portalLogin = (): void => {
this.stores.mainStore.setUserLoginState('loading');
const { appStore } = this.stores;
const { config } = appStore;
window.addEventListener('arcgis:auth:hash', (event) => {
console.log('OAuth response:', event.detail);
IdentityManager.setOAuthResponseHash(event.detail);
});
const oAuthInfo = new OAuthInfo({
appId: this.stores.appStore.config.main.appRegistration.appId,
portalUrl: this.stores.appStore.config.main.appRegistration.portalUrl,
});
this.portal = new Portal({ url: config.main.appRegistration.portalUrl });
this.portal.load().then(() => {
IdentityManager.registerOAuthInfos([oAuthInfo]);
this.stores.mainStore.helperServices = this.portal.helperServices;
this.stores.mainStore.portal = this.portal;
IdentityManager.checkSignInStatus(`${oAuthInfo.portalUrl}/sharing`)
.then((signInEvt: Credential) => {
this.stores.mainStore.user = signInEvt;
this.getGroupsTitleOfUser().then((groups: string[]) => {
this.stores.mainStore.userGroups = groups;
this.stores.mainStore.setUserLoginState('loaded');
console.log(`User ${signInEvt.userId} successful signed in. Assigned groups: ${this.stores.mainStore.userGroups}`, signInEvt);
});
})
.catch((error: Error) => {
console.log(error.message);
IdentityManager.getCredential(`${oAuthInfo.portalUrl}/sharing`, {
oAuthPopupConfirmation: false,
}).then((signInEvt: Credential) => {
this.stores.mainStore.user = signInEvt;
this.getGroupsTitleOfUser().then((groups: string[]) => {
this.stores.mainStore.userGroups = groups;
this.stores.mainStore.setUserLoginState('loaded');
console.log(`User ${signInEvt.userId} successful signed in. Assigned groups: ${this.stores.mainStore.userGroups}`, signInEvt);
});
});
});
});
};