Szlaski_Daniel | 2017-11-09 12:45:43 UTC | #1
Hi,
We've got Inbound Script with custom page embeeded there. What we do, we execute below code (user context) to log-in. Because we're doing this from a Script (the same browser) - we do not have a popup window, but during every reload we login again / generate new Token.
Is there a better way to obtain from API Token inside a Script?
const platformClient = require('platformClient'); client = platformClient.ApiClient.instance; var _token = client.authentications["PureCloud Auth"].accessToken;
if (_token) { // do Authenticated stuff here
} else { // token not available - SignIn first signIn(); }
Thanks, Daniel
tim.smith | 2017-11-09 16:18:50 UTC | #2
You can probably use local storage in the browser or a cookie to store the token between page reloads. How you go about it depends on how your app is written.
Szlaski_Daniel | 2017-11-09 16:33:03 UTC | #3
I do not believe that javascript is allowed for crossdomain lookup. PureCloud webPages are hosted from mypurecloud.ie, but embeeded Script it a different domain. Storage / Cookies are not shared between them.
I've thought that there is a cleaner way to solve that.
tim.smith | 2017-11-09 17:11:37 UTC | #4
I wasn't suggesting to try and steal the token from the PureCloud UI. I'm saying that you can authenticate and use local storage or a cookie to track your auth token. The SDK has a feature for this, though I haven't tested it from a script page. See the section Access Token persistence in the JavaScript SDK documentation.
Szlaski_Daniel | 2017-11-09 17:50:51 UTC | #5
I see your point. That could be also a nice feature, but looks like it's not honored.
From my tests it looks that even if I put: client.setPersistSettings(true);
before login function - token is different each time.
tim.smith | 2017-11-13 18:00:11 UTC | #6
I created a test app to verify that token persistence works from within a script. It does. Here's the code: https://github.com/PrinceNebulon/purecloud-user-data-widget deployed to https://princenebulon.github.io/purecloud-user-data-widget/index.html. I verified that in the network tab in the chrome dev tools no requests were being made to obtain a new token.
system | 2017-12-14 18:00:29 UTC | #7
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 2078