Skip to content

Commit

Permalink
feat(:snowman:): add basic support for accessing secure non-federated…
Browse files Browse the repository at this point in the history
… services

AFFECTS PACKAGES:
@esri/arcgis-rest-auth

ISSUES CLOSED: Esri#174
  • Loading branch information
jgravois committed Feb 12, 2019
1 parent bbdac40 commit 0fb583f
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions packages/arcgis-rest-auth/src/UserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export interface IOauth2Options {
*/
refreshTokenTTL?: number;

/**
* An unfederated ArcGIS Server instance that recognizes the supplied credentials.
*/
server?: string;

/**
* The locale assumed to render the login page.
*
Expand Down Expand Up @@ -186,6 +191,11 @@ export interface IUserSessionOptions {
* Duration (in minutes) that a refresh token will be valid.
*/
refreshTokenTTL?: number;

/**
* An unfederated ArcGIS Server instance that recognizes the supplied credentials.
*/
server?: string;
}

/**
Expand Down Expand Up @@ -730,25 +740,43 @@ export class UserSession implements IAuthenticationManager {

this._pendingTokenRequests[root] = request(`${root}/rest/info`)
.then((response: any) => {
return response.owningSystemUrl;
return response;
})
.then(owningSystemUrl => {
/**
* if this server is not owned by this portal or the stand-alone
* instance of ArcGIS Server doesn't advertise federation,
* bail out with an error since we know we wont
* be able to generate a token
*/
if (
!owningSystemUrl ||
!new RegExp(owningSystemUrl, "i").test(this.portal)
.then(response => {
if (response.owningSystemUrl) {
/**
* if this server is not owned by this portal
* bail out with an error since we know we wont
* be able to generate a token
*/
if (!new RegExp(response.owningSystemUrl, "i").test(this.portal)) {
throw new ArcGISAuthError(
`${url} is not federated with ${this.portal}.`,
"NOT_FEDERATED"
);
} else {
return request(
`${response.owningSystemUrl}/sharing/rest/info`,
requestOptions
);
}
} else if (
response.authInfo &&
this.trustedServers[root] !== undefined
) {
/**
* if its a stand-alone instance of ArcGIS Server that doesn't advertise
* federation at all and the root url is recognized, use its built in token endpoint.
*/
return new Promise((resolve, reject) => {
resolve({ authInfo: response.authInfo });
});
} else {
throw new ArcGISAuthError(
`${url} is not federated with ${this.portal}.`,
"NOT_FEDERATED"
);
}
return request(`${owningSystemUrl}/sharing/rest/info`, requestOptions);
})
.then((response: any) => {
return response.authInfo.tokenServicesUrl;
Expand All @@ -768,7 +796,8 @@ export class UserSession implements IAuthenticationManager {
params: {
username: this.username,
password: this.password,
expiration: this.tokenDuration
expiration: this.tokenDuration,
client: "referer"
}
}).then((response: any) => {
this._token = response.token;
Expand Down

0 comments on commit 0fb583f

Please sign in to comment.