Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public refreshSession(
requestOptions?: ITokenRequestOptions
): Promise {
// make sure subsequent calls to getUser() don't returned cached metadata
this._user = null;
if (this.username && this.password) {
return this.refreshWithUsernameAndPassword(requestOptions);
}
if (this.clientId && this.refreshToken) {
return this.refreshWithRefreshToken();
}
return Promise.reject(new ArcGISAuthError("Unable to refresh token."));
}
.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 {
/**
* if the server is federated, use the relevant token endpoint.
*/
return request(
`${response.owningSystemUrl}/sharing/rest/info`,
requestOptions
);
}
} else if (
response.authInfo &&
this.trustedServers[root] !== undefined
) {
);
win.close();
return undefined;
}
if (win !== win.parent) {
win.parent[`__ESRI_REST_AUTH_HANDLER_${clientId}`](
error ? JSON.stringify(error) : undefined,
JSON.stringify(oauthInfo)
);
win.close();
return undefined;
}
if (error) {
throw new ArcGISAuthError(error.errorMessage, error.error);
}
return new UserSession({
clientId,
portal,
ssl: oauthInfo.ssl,
token: oauthInfo.token,
tokenExpires: oauthInfo.expires,
username: oauthInfo.username
});
}
win[`__ESRI_REST_AUTH_HANDLER_${clientId}`] = function(
errorString: any,
oauthInfoString: string
) {
if (errorString) {
const error = JSON.parse(errorString);
session.reject(new ArcGISAuthError(error.errorMessage, error.error));
return;
}
if (oauthInfoString) {
const oauthInfo = JSON.parse(oauthInfoString);
session.resolve(
new UserSession({
clientId,
portal,
ssl: oauthInfo.ssl,
token: oauthInfo.token,
tokenExpires: new Date(oauthInfo.expires),
username: oauthInfo.username
})
);
}
return new Promise((resolve, reject) => {
reject(
new request.ArcGISAuthError(
"Filename must have an extension indicating its type"
)
);
});
}