@esri/arcgis-rest-auth
Version:
Authentication helpers for @esri/arcgis-rest-js.
61 lines (60 loc) • 2.54 kB
TypeScript
import { IAuthenticationManager, ITokenRequestOptions } from "@esri/arcgis-rest-request";
export interface IApplicationSessionOptions {
/**
* Client ID of your application. Can be obtained by registering an application
* on [ArcGIS for Developers](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/#registering-your-application),
* [ArcGIS Online](http://doc.arcgis.com/en/arcgis-online/share-maps/add-items.htm#ESRI_SECTION1_0D1B620254F745AE84F394289F8AF44B) or on your instance of ArcGIS Enterprise.
*/
clientId: string;
/**
* A Client Secret is also obtained by registering an application
* on [ArcGIS for Developers](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/#registering-your-application),
* [ArcGIS Online](http://doc.arcgis.com/en/arcgis-online/share-maps/add-items.htm#ESRI_SECTION1_0D1B620254F745AE84F394289F8AF44B) or on your instance of ArcGIS Enterprise. Treat it like a password.
*/
clientSecret: string;
/**
* OAuth 2.0 access token from a previous application session.
*/
token?: string;
/**
* Expiration date for the `token`
*/
expires?: Date;
/**
* URL of ArcGIS REST base, defaults to "https://www.arcgis.com/sharing/rest"
*/
portal?: string;
/**
* Duration of requested tokens in minutes. defaults to 7200 (5 days).
*/
duration?: number;
}
/**
* ```js
* import { ApplicationSession } from '@esri/arcgis-rest-auth';
* const session = new ApplicationSession({
* clientId: "abc123",
* clientSecret: "sshhhhhh"
* })
* // visit https://developers.arcgis.com to generate your own clientid and secret
* ```
* You can use [App Login](/arcgis-rest-js/guides/node/) to access premium content and services in ArcGIS Online.
*
*/
export declare class ApplicationSession implements IAuthenticationManager {
portal: string;
private clientId;
private clientSecret;
private token;
private expires;
private duration;
/**
* Internal object to keep track of pending token requests. Used to prevent
* duplicate token requests.
*/
private _pendingTokenRequest;
constructor(options: IApplicationSessionOptions);
getToken(url: string, requestOptions?: ITokenRequestOptions): Promise<string>;
refreshToken(requestOptions?: ITokenRequestOptions): Promise<string>;
refreshSession(): Promise<this>;
}