@esri/arcgis-rest-auth
Version:
Authentication helpers for @esri/arcgis-rest-js.
27 lines • 1.1 kB
JavaScript
;
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchToken = void 0;
var arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
function fetchToken(url, requestOptions) {
var options = requestOptions;
// we generate a response, so we can't return the raw response
options.rawResponse = false;
return arcgis_rest_request_1.request(url, options).then(function (response) {
var r = {
token: response.access_token,
username: response.username,
expires: new Date(
// convert seconds in response to milliseconds and add the value to the current time to calculate a static expiration timestamp
Date.now() + (response.expires_in * 1000 - 1000)),
ssl: response.ssl === true
};
if (response.refresh_token) {
r.refreshToken = response.refresh_token;
}
return r;
});
}
exports.fetchToken = fetchToken;
//# sourceMappingURL=fetch-token.js.map