Skip to content

Commit

Permalink
fix: platformSelf to send cookies and append f=json in url
Browse files Browse the repository at this point in the history
  • Loading branch information
dbouwman committed Nov 13, 2020
1 parent 2d36c52 commit ed81919
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/arcgis-rest-auth/src/app-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,20 @@ export function platformSelf(
redirectUri: string,
portal: string = "https://www.arcgis.com/sharing/rest"
): Promise<IPlatformSelfResponse> {
const url = `${portal}/oauth2/platformSelf`;
// TEMPORARY: the f=json should not be needed, but currently is
const url = `${portal}/oauth2/platformSelf?f=json`;
const ro = {
method: "POST",
headers: {
"X-Esri-Auth-Client-Id": clientId,
"X-Esri-Auth-Redirect-Uri": redirectUri,
},
// We need to ensure the cookies are sent as that's
// what the API uses to convert things
credentials: "include",
params: {
f: "json",
},
} as IRequestOptions;
// make the request and return the token
return request(url, ro);
Expand Down
4 changes: 2 additions & 2 deletions packages/arcgis-rest-auth/test/app-tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("app-token functions: ", () => {
describe("platformSelf:", () => {
it("makes a request to /oauth2/platformSelf passing params", () => {
const PLATFORM_SELF_URL =
"https://www.arcgis.com/sharing/rest/oauth2/platformSelf";
"https://www.arcgis.com/sharing/rest/oauth2/platformSelf?f=json";
fetchMock.postOnce(PLATFORM_SELF_URL, {
username: "jsmith",
token: "APP-TOKEN",
Expand All @@ -73,7 +73,7 @@ describe("app-token functions: ", () => {
});
it("takes a portalUrl", () => {
const PORTAL_BASE_URL = "https://my-portal.com/instance/sharing/rest";
const PORTAL_PLATFORM_SELF_URL = `${PORTAL_BASE_URL}/oauth2/platformSelf`;
const PORTAL_PLATFORM_SELF_URL = `${PORTAL_BASE_URL}/oauth2/platformSelf?f=json`;
fetchMock.postOnce(PORTAL_PLATFORM_SELF_URL, {
username: "jsmith",
token: "APP-TOKEN",
Expand Down

0 comments on commit ed81919

Please sign in to comment.