Skip to content

Commit 0c24941

Browse files
Merge pull request #157 from 03-CiprianoG/master
Add __RequestVerificationToken header for Portals Web API auth
2 parents c6d005e + eac744d commit 0c24941

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/client/RequestClient.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ export class RequestClient {
9999
request.headers["Authorization"] = "Bearer " + (token.hasOwnProperty("accessToken") ? (token as AccessToken).accessToken : token);
100100
}
101101

102+
if (Utility.isRunningWithinPortals()) {
103+
try {
104+
const token = await (window as any).shell.getTokenDeferred();
105+
request.headers["__RequestVerificationToken"] = token;
106+
} catch (error) {
107+
throw new Error("Unable to fetch token from shell. Error: " + (error as Error)?.message);
108+
}
109+
}
110+
102111
const url = request.apiConfig ? request.apiConfig.url : config.dataApi.url;
103112

104113
return await executeRequest({

0 commit comments

Comments
 (0)