UNPKG

@esri/arcgis-rest-auth

Version:

Authentication helpers for @esri/arcgis-rest-js.

23 lines 936 B
/* Copyright (c) 2017 Environmental Systems Research Institute, Inc. * Apache-2.0 */ import { request } from "@esri/arcgis-rest-request"; export function fetchToken(url, requestOptions) { var options = requestOptions; // we generate a response, so we can't return the raw response options.rawResponse = false; return 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; }); } //# sourceMappingURL=fetch-token.js.map