Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Session Token in Custom Object

SergeiBakhaev
Contributor III

Hello!

 

To use WS API in my custom objects, I need session token.

Since 6.1 it was possible to get it like this:

var sessionToken = parent.parent.ArcherApp.globals.workpointFeatures.SessionToken;

But, I've recently updated to 6.4 SP1 P1, and ArcherApp.globals.workpointFeatures is now a JSON string encoded into base64.

That requires me to do decoding, and then double deserialization to parse JSON:

var sessionToken = Sys.Serialization.JavaScriptSerializer.deserialize(Sys.Serialization.JavaScriptSerializer.deserialize(atob(parent.parent.ArcherApp.globals.workpointFeatures))).SessionToken;

Is there any easier way to get session token?

1 ACCEPTED SOLUTION

Accepted Solutions

DavidPetty
Archer Employee
Archer Employee

Nope

 

This is what I use, and it about the same thing your're doing:

var sessionToken = JSON.parse(JSON.parse(atob(parent.parent.ArcherApp.globals.workpointFeatures))).SessionToken‍‍

 Advisory Consultant

View solution in original post

9 REPLIES 9

DavidPetty
Archer Employee
Archer Employee

Nope

 

This is what I use, and it about the same thing your're doing:

var sessionToken = JSON.parse(JSON.parse(atob(parent.parent.ArcherApp.globals.workpointFeatures))).SessionToken‍‍

 Advisory Consultant

What about Headers? Like 

x-csrf-token

Definitely not the user session token

 

It's the Cross-Site Request Forgery token.

 

The session token is also in a read-only cookie; client side scripts can't read it.

 Advisory Consultant

Ah, okay, but I meant, is not it so that all session elements are stored also in Headers?

Not really.  Either in application variables, ASP.NET viewstate or cookies.

 Advisory Consultant

Great, thanks!

STEPHENCHAN
Contributor III

Hi David,  The following doesn't seem to work anymore.  Is there an alternative way to obtain the session token?

 

var sessionToken = JSON.parse(JSON.parse(atob(parent.parent.ArcherApp.globals.workpointFeatures))).SessionToken‍‍‍

 

@STEPHENCHAN seems to be working fine for me on 6.12 P5

DavidPetty_0-1682514922880.png

 

 Advisory Consultant

Thanks. I got it to work eventually.   It was returning undefined initially.