Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: platformSelf to send cookies and append f=json in url #778

Merged
merged 1 commit into from Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/arcgis-rest-auth/src/app-tokens.ts
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,
},
Comment on lines 78 to 81
Copy link
Member

@tomwayson tomwayson Nov 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbouwman @noahmulfinger I wonder if we can use the existence of headers that start w/ "X-Esri-Auth-" as the signal to request() that it should set credentials: "include"?

Rather than introduce any new properties on IRequestOptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable. Another option would be adding a fetchOptions param or something similar. That way we could allow extra overrides for any future edge cases like this.

// 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
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