I have a scripting tool on my Portal which works fine if the user is signed in. However, if the user is not signed in, the scripting tool obviously doesn't work.
I also have a token, which has been generated earlier (though not much earlier - the token is still current).
Is it possible to use this token to run my scripting tool, and if so, how should it be passed into the URL? This is a very basic version of how it works:
window.open("https://myserver.com/server/rest/services/MyPrintLayouts/ScriptX01_AGP2_9/GPServer/ScriptX01/submitJob?Id=" + vId + "&FileDestination=" + vDestination + "&env%3AoutSR=&env%3AprocessSR=&returnZ=false&returnM=false&returnTrueCurves=false&context=&f=html", '_blank');
I've tried adding a
&token=" + token
Extra token parameter in there but that's not working. Each time it gets called, if the user isn't signed in, it will go to the sign in screen.
Michael, can you share the section of code being used to generate the token?
Sure. Sorry I've only just gotten round to this now, been in the field a bit. See below for the edited version:
var tokenUrl = "https://myserver.com/portal/sharing/rest/generateToken";
var requestParams = {
method: "post",
query: {
f: 'json',
username: 'MyUsername',
password: 'MyPassword',
referer: window.location.origin
}
};
var myRequest = esriRequest(tokenUrl, requestParams);
myRequest.then(function(response){
var token = response.data.token;
esriId.registerToken({
server: "https://myserver.com/portal/sharing/rest",
token: token
});
initMap();
});
As I say, I have a tool which I can call using the following:
https://myserver.com/server/rest/services/MyPrintLayouts/ScriptX01_AGP2_9/GPServer/ScriptX01/submitJob?&MyId=%7B<MyIdAsGUID>%7D&FileDestination=C%3A%5Ctemp%5C%7B<MyFilename>%7D.pdf&env%3AoutSR=&env%3AprocessSR=&returnZ=false&returnM=false&returnTrueCurves=false&context=&f=html
If I'm logged into the server already, then it works fine. If I'm not however, I get presented with a login screen. I'd like to be able to use the token to access it, which doesn't seem to work if I include it in the URL (which I assume I'm doing wrong).
Huh, go figure. It may have been running all along, I'm unsure.
In my latest code, I made a couple of little tweaks to my requestparams. It is instead:
var requestParams = {
method: "post",
query: {
f: 'json',
username: 'MyUsername',
password: 'MyPassword',
client: 'requestip'
}
};
And added the token to my url, at the end.
In any case, I'm still getting the signin screen, which I believe is because I'm calling the job wrong (at the moment I'm just using a window.open to call the url), but the job still calls and executes. I just assumed it wasn't because of the login screen.
Now to find a better way to call the job... (eventually, because now other tasks have popped up)