How to get the token for logged-in user in portal ?

325
1
09-16-2019 07:40 PM
MichalGasparovic1
New Contributor III

Hi guys,

this might seem trivial but I can't get my head around why IdentityManager's credentials for the logged in user have the token=undefined, though I can clearly see the token in the esri_auth cookie and esri js api is using this token to get access to the portal items... ?

 const portal: esri.Portal = new this.esriModules.Portal({ authMode: 'immediate' });
portal.load().then(async () => {
const {username: userId, fullName, email, thumbnailUrl} = portal.user;
const {token, userId, server} = await this.identityManager.getCredential(portal.url, {
oAuthPopupConfirmation: false
});

// everything is populated except the token
// tried all these... no luck
const val1 = await this.identityManager.checkSignInStatus(portal.url);
const val2 = await this.identityManager.checkSignInStatus(portal.url + '/sharing');


const cred1 = await this.identityManager.findCredential(portal.url)
const cred2 = await this.identityManager.findCredential(portal.url + '/sharing')
const cred3 = await this.identityManager.findCredential(portal.url + '/sharing/rest')
const cred4 = await this.identityManager.findCredential(portal.url, userId)
const cred5 = await this.identityManager.findCredential(portal.url + '/sharing', userId)
const cred6 = await this.identityManager.findCredential(portal.url + '/sharing/rest', userId)

I'm sure I'm missing something basic....

Thank you!

Tags (1)
0 Kudos
1 Reply
RhysDonoghue2
New Contributor III

hi Michal,

It's a bit late for my reply here but in case you are still trying to do this:

 portal.load().then(async () => { console.log(portal.credential.token); });

 

Cheers,

Rhys 

0 Kudos