Skip to content

Commit

Permalink
fix(portal): fetch tokens for rest admin requests to services federat…
Browse files Browse the repository at this point in the history
…ed with ArcGIS Enterprise too

AFFECTS PACKAGES:
@esri/arcgis-rest-auth

ISSUES CLOSED: #329
  • Loading branch information
jgravois committed Sep 19, 2018
1 parent 106cc8a commit 79dda00
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/arcgis-rest-auth/src/UserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,8 @@ export class UserSession implements IAuthenticationManager {
url: string,
requestOptions?: ITokenRequestOptions
) {
const [root] = url.split("/rest/services/");
// requests to /rest/services/ and /rest/admin/services/ are both valid
const [root] = url.split(/\/rest(\/admin)?\/services\//);
const existingToken = this.trustedServers[root];

if (existingToken && existingToken.expires.getTime() > Date.now()) {
Expand Down
51 changes: 51 additions & 0 deletions packages/arcgis-rest-auth/test/UserSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,57 @@ describe("UserSession", () => {
});
});

it("should generate a token for an untrusted, federated server admin call", done => {
const session = new UserSession({
clientId: "id",
token: "token",
refreshToken: "refresh",
tokenExpires: TOMORROW,
portal: "https://gis.city.gov/sharing/rest"
});

fetchMock.postOnce("https://gisservices.city.gov/public/rest/info", {
currentVersion: 10.51,
fullVersion: "10.5.1.120",
owningSystemUrl: "https://gis.city.gov",
authInfo: {
isTokenBasedSecurity: true,
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken"
}
});

fetchMock.postOnce("https://gis.city.gov/sharing/rest/info", {
owningSystemUrl: "http://gis.city.gov",
authInfo: {
tokenServicesUrl: "https://gis.city.gov/sharing/generateToken",
isTokenBasedSecurity: true
}
});

fetchMock.postOnce("https://gis.city.gov/sharing/generateToken", {
token: "serverToken",
expires: TOMORROW
});

session
.getToken(
"https://gisservices.city.gov/public/rest/admin/services/trees/FeatureServer/addToDefinition"
)
.then(token => {
expect(token).toBe("serverToken");
return session.getToken(
"https://gisservices.city.gov/public/rest/admin/services/trees/FeatureServer/addToDefinition"
);
})
.then(token => {
expect(token).toBe("serverToken");
done();
})
.catch(e => {
fail(e);
});
});

it("should generate a token for an untrusted, federated server with user credentials", done => {
const session = new UserSession({
username: "c@sey",
Expand Down

0 comments on commit 79dda00

Please sign in to comment.