RestUtility does not add token to url
Hi,
In a custom module, I'm trying to make a request to a (geocortex) REST endpoint. This works, but not in a secured site. In that case I get an error message The current user cannot access the desired resource .
While looking at the actual request, I noticed that it does not contain a token, and if I add it manually, the request is succesful. Is this a bug in the HTML viewer, or should I add it myself? I seem to remember that this did work in the SL viewer.
Typescript code:
var restUtility = new geocortex.essentials.RestUtility();
restUtility.getCustomRestEndpoint(url, "", (result: geocortex.essentials.RestEndpointResult) => {
if (!result.error) {
// Process results
}
}, this.queryErrorHandler, null);
-
Hi Alejandro,
Thanks for that. The 2nd parameter of getCustomRestEndpoint should be a string though, so I guess it would have to be something like this "token={0}".format(this.myToken) ? BTW, isn't the RestUtility supposed to add the token by itself?
One more question: I can get the token by listening to the AuthenticationSucceeded event, but what happens if that token expires? Will the system automatically generate a new token and raise the event again ? (What's the expiration time anyway?)
0 -
I think the definition for getCustomRestEndpoint() in essentials.d.ts is not correct. The 2nd parameter is defined as a string:
public getCustomRestEndpoint(endpointUrl: string, content: string , completeHandler: (res: essentials.RestEndpointResult) => void, errorHandler: (error: Error) => void, options: Object): void;
but is handled as an object. For example, I can't pass { "abc": "xyz" } to it ('Supplied parameters do not match any signature of call target'), but if I pass "abc=xyz", the parameters in the url look like &0=a&1=b&2=c&3=%3D&4=x&5=y&6=z&.
What works now is to just ignore the 2nd param, and add any param to the url directly:
restUtility.getCustomRestEndpoint("{0}&token={1}".format(url, this.myToken), "", (result: geocortex.essentials.RestEndpointResult) => { ...
0 -
I had that exact same issue, I just went into the d.ts file and changed the defiinition to content: any so I could pass in a dictionary of values
That's the way it was defined in the 5.1 api or so, it changed recently to content:string, not sure why.
0 -
(version number off), somewhere like 2.1 => 2.3
0 -
Hi Alejandro,
Thanks for the clarification, it does make sense to not include the token automatically. I think I got confused by the similar method in the SL viewer, which does that. At least, IIRC.
Berend
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
5 Kommentare