@esri/arcgis-rest-auth 3.4.2 → 4.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/.ultra.cache.json +1 -0
  2. package/CHANGELOG.md +110 -0
  3. package/README.md +5 -5
  4. package/dist/bundled/auth.esm.js +7 -0
  5. package/dist/bundled/auth.esm.js.map +1 -0
  6. package/dist/bundled/auth.esm.min.js +7 -0
  7. package/dist/bundled/auth.esm.min.js.map +1 -0
  8. package/dist/bundled/auth.umd.js +112 -0
  9. package/dist/bundled/auth.umd.js.map +1 -0
  10. package/dist/bundled/auth.umd.min.js +7 -0
  11. package/dist/bundled/auth.umd.min.js.map +1 -0
  12. package/dist/cjs/index.js +20 -0
  13. package/dist/cjs/index.js.map +1 -0
  14. package/dist/cjs/package.json +3 -0
  15. package/dist/esm/index.d.ts +4 -9
  16. package/dist/esm/index.js +1 -8
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/package.json +3 -0
  19. package/package.json +44 -45
  20. package/src/index.ts +34 -0
  21. package/tsconfig.json +6 -0
  22. package/dist/esm/ApiKey.d.ts +0 -26
  23. package/dist/esm/ApiKey.js +0 -23
  24. package/dist/esm/ApiKey.js.map +0 -1
  25. package/dist/esm/ApplicationSession.d.ts +0 -60
  26. package/dist/esm/ApplicationSession.js +0 -59
  27. package/dist/esm/ApplicationSession.js.map +0 -1
  28. package/dist/esm/UserSession.d.ts +0 -496
  29. package/dist/esm/UserSession.js +0 -890
  30. package/dist/esm/UserSession.js.map +0 -1
  31. package/dist/esm/app-tokens.d.ts +0 -87
  32. package/dist/esm/app-tokens.js +0 -104
  33. package/dist/esm/app-tokens.js.map +0 -1
  34. package/dist/esm/authenticated-request-options.d.ts +0 -18
  35. package/dist/esm/authenticated-request-options.js +0 -3
  36. package/dist/esm/authenticated-request-options.js.map +0 -1
  37. package/dist/esm/federation-utils.d.ts +0 -5
  38. package/dist/esm/federation-utils.js +0 -59
  39. package/dist/esm/federation-utils.js.map +0 -1
  40. package/dist/esm/fetch-token.d.ts +0 -9
  41. package/dist/esm/fetch-token.js +0 -23
  42. package/dist/esm/fetch-token.js.map +0 -1
  43. package/dist/esm/generate-token.d.ts +0 -7
  44. package/dist/esm/generate-token.js +0 -17
  45. package/dist/esm/generate-token.js.map +0 -1
  46. package/dist/esm/validate-app-access.d.ts +0 -47
  47. package/dist/esm/validate-app-access.js +0 -52
  48. package/dist/esm/validate-app-access.js.map +0 -1
  49. package/dist/node/ApiKey.js +0 -26
  50. package/dist/node/ApiKey.js.map +0 -1
  51. package/dist/node/ApplicationSession.js +0 -62
  52. package/dist/node/ApplicationSession.js.map +0 -1
  53. package/dist/node/UserSession.js +0 -893
  54. package/dist/node/UserSession.js.map +0 -1
  55. package/dist/node/app-tokens.js +0 -109
  56. package/dist/node/app-tokens.js.map +0 -1
  57. package/dist/node/authenticated-request-options.js +0 -5
  58. package/dist/node/authenticated-request-options.js.map +0 -1
  59. package/dist/node/federation-utils.js +0 -67
  60. package/dist/node/federation-utils.js.map +0 -1
  61. package/dist/node/fetch-token.js +0 -27
  62. package/dist/node/fetch-token.js.map +0 -1
  63. package/dist/node/generate-token.js +0 -21
  64. package/dist/node/generate-token.js.map +0 -1
  65. package/dist/node/index.js +0 -14
  66. package/dist/node/index.js.map +0 -1
  67. package/dist/node/validate-app-access.js +0 -56
  68. package/dist/node/validate-app-access.js.map +0 -1
  69. package/dist/umd/auth.umd.js +0 -1253
  70. package/dist/umd/auth.umd.js.map +0 -1
  71. package/dist/umd/auth.umd.min.js +0 -7
  72. package/dist/umd/auth.umd.min.js.map +0 -1
@@ -1,60 +0,0 @@
1
- import { IAuthenticationManager, ITokenRequestOptions } from "@esri/arcgis-rest-request";
2
- export interface IApplicationSessionOptions {
3
- /**
4
- * Client ID of your application. Can be obtained by registering an application
5
- * on [ArcGIS for Developers](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/#registering-your-application),
6
- * [ArcGIS Online](http://doc.arcgis.com/en/arcgis-online/share-maps/add-items.htm#ESRI_SECTION1_0D1B620254F745AE84F394289F8AF44B) or on your instance of ArcGIS Enterprise.
7
- */
8
- clientId: string;
9
- /**
10
- * A Client Secret is also obtained by registering an application
11
- * on [ArcGIS for Developers](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/#registering-your-application),
12
- * [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.
13
- */
14
- clientSecret: string;
15
- /**
16
- * OAuth 2.0 access token from a previous application session.
17
- */
18
- token?: string;
19
- /**
20
- * Expiration date for the `token`
21
- */
22
- expires?: Date;
23
- /**
24
- * URL of ArcGIS REST base, defaults to "https://www.arcgis.com/sharing/rest"
25
- */
26
- portal?: string;
27
- /**
28
- * Duration of requested tokens in minutes. defaults to 7200 (5 days).
29
- */
30
- duration?: number;
31
- }
32
- /**
33
- * ```js
34
- * import { ApplicationSession } from '@esri/arcgis-rest-auth';
35
- * const session = new ApplicationSession({
36
- * clientId: "abc123",
37
- * clientSecret: "sshhhhhh"
38
- * })
39
- * // visit https://developers.arcgis.com to generate your own clientid and secret
40
- * ```
41
- * You can use [App Login](/arcgis-rest-js/guides/node/) to access premium content and services in ArcGIS Online.
42
- *
43
- */
44
- export declare class ApplicationSession implements IAuthenticationManager {
45
- portal: string;
46
- private clientId;
47
- private clientSecret;
48
- private token;
49
- private expires;
50
- private duration;
51
- /**
52
- * Internal object to keep track of pending token requests. Used to prevent
53
- * duplicate token requests.
54
- */
55
- private _pendingTokenRequest;
56
- constructor(options: IApplicationSessionOptions);
57
- getToken(url: string, requestOptions?: ITokenRequestOptions): Promise<string>;
58
- refreshToken(requestOptions?: ITokenRequestOptions): Promise<string>;
59
- refreshSession(): Promise<this>;
60
- }
@@ -1,59 +0,0 @@
1
- /* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
2
- * Apache-2.0 */
3
- import { __assign } from "tslib";
4
- import { fetchToken } from "./fetch-token";
5
- /**
6
- * ```js
7
- * import { ApplicationSession } from '@esri/arcgis-rest-auth';
8
- * const session = new ApplicationSession({
9
- * clientId: "abc123",
10
- * clientSecret: "sshhhhhh"
11
- * })
12
- * // visit https://developers.arcgis.com to generate your own clientid and secret
13
- * ```
14
- * You can use [App Login](/arcgis-rest-js/guides/node/) to access premium content and services in ArcGIS Online.
15
- *
16
- */
17
- var ApplicationSession = /** @class */ (function () {
18
- function ApplicationSession(options) {
19
- this.clientId = options.clientId;
20
- this.clientSecret = options.clientSecret;
21
- this.token = options.token;
22
- this.expires = options.expires;
23
- this.portal = options.portal || "https://www.arcgis.com/sharing/rest";
24
- this.duration = options.duration || 7200;
25
- }
26
- // URL is not actually read or passed through.
27
- ApplicationSession.prototype.getToken = function (url, requestOptions) {
28
- if (this.token && this.expires && this.expires.getTime() > Date.now()) {
29
- return Promise.resolve(this.token);
30
- }
31
- if (this._pendingTokenRequest) {
32
- return this._pendingTokenRequest;
33
- }
34
- this._pendingTokenRequest = this.refreshToken(requestOptions);
35
- return this._pendingTokenRequest;
36
- };
37
- ApplicationSession.prototype.refreshToken = function (requestOptions) {
38
- var _this = this;
39
- var options = __assign({ params: {
40
- client_id: this.clientId,
41
- client_secret: this.clientSecret,
42
- grant_type: "client_credentials",
43
- expiration: this.duration
44
- } }, requestOptions);
45
- return fetchToken(this.portal + "/oauth2/token/", options).then(function (response) {
46
- _this._pendingTokenRequest = null;
47
- _this.token = response.token;
48
- _this.expires = response.expires;
49
- return response.token;
50
- });
51
- };
52
- ApplicationSession.prototype.refreshSession = function () {
53
- var _this = this;
54
- return this.refreshToken().then(function () { return _this; });
55
- };
56
- return ApplicationSession;
57
- }());
58
- export { ApplicationSession };
59
- //# sourceMappingURL=ApplicationSession.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApplicationSession.js","sourceRoot":"","sources":["../../src/ApplicationSession.ts"],"names":[],"mappings":"AAAA;gBACgB;;AAMhB,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAsC3C;;;;;;;;;;;GAWG;AACH;IAcE,4BAAY,OAAmC;QAC7C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,qCAAqC,CAAC;QACtE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC;IAC3C,CAAC;IAED,8CAA8C;IACvC,qCAAQ,GAAf,UACE,GAAW,EACX,cAAqC;QAErC,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE;YACrE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpC;QAED,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC7B,OAAO,IAAI,CAAC,oBAAoB,CAAC;SAClC;QAED,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;QAE9D,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACnC,CAAC;IAEM,yCAAY,GAAnB,UAAoB,cAAqC;QAAzD,iBAkBC;QAjBC,IAAM,OAAO,cACX,MAAM,EAAE;gBACN,SAAS,EAAE,IAAI,CAAC,QAAQ;gBACxB,aAAa,EAAE,IAAI,CAAC,YAAY;gBAChC,UAAU,EAAE,oBAAoB;gBAChC,UAAU,EAAE,IAAI,CAAC,QAAQ;aAC1B,IACE,cAAc,CAClB,CAAC;QACF,OAAO,UAAU,CAAI,IAAI,CAAC,MAAM,mBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI,CAC7D,UAAA,QAAQ;YACN,KAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;YACjC,KAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;YAC5B,KAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;YAChC,OAAO,QAAQ,CAAC,KAAK,CAAC;QACxB,CAAC,CACF,CAAC;IACJ,CAAC;IAEM,2CAAc,GAArB;QAAA,iBAEC;QADC,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,cAAM,OAAA,KAAI,EAAJ,CAAI,CAAC,CAAC;IAC9C,CAAC;IACH,yBAAC;AAAD,CAAC,AAhED,IAgEC"}
@@ -1,496 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * /generateToken returns a token that cannot be refreshed.
4
- *
5
- * oauth2/token can return a token *and* a refreshToken.
6
- * up until the refreshToken expires, you can use it (and a clientId)
7
- * to fetch fresh credentials without a username and password.
8
- *
9
- * the catch is that this 'authorization_code' flow is only utilized
10
- * by server based OAuth 2 Node.js applications that call /authorize first.
11
- */
12
- import * as http from "http";
13
- import { IRequestOptions, IAuthenticationManager, ITokenRequestOptions } from "@esri/arcgis-rest-request";
14
- import { IUser } from "@esri/arcgis-rest-types";
15
- import { IAppAccess } from "./validate-app-access";
16
- export declare type AuthenticationProvider = "arcgis" | "facebook" | "google" | "github" | "apple";
17
- /**
18
- * Represents a [credential](https://developers.arcgis.com/javascript/latest/api-reference/esri-identity-Credential.html)
19
- * object used to access a secure ArcGIS resource.
20
- */
21
- export interface ICredential {
22
- expires: number;
23
- server: string;
24
- ssl: boolean;
25
- token: string;
26
- userId: string;
27
- }
28
- /**
29
- * Options for static OAuth 2.0 helper methods on `UserSession`.
30
- */
31
- export interface IOAuth2Options {
32
- /**
33
- * Client ID of your application. Can be obtained by registering an application
34
- * on [ArcGIS for Developers](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/#registering-your-application),
35
- * [ArcGIS Online](http://doc.arcgis.com/en/arcgis-online/share-maps/add-items.htm#ESRI_SECTION1_0D1B620254F745AE84F394289F8AF44B) or on your instance of ArcGIS Enterprise.
36
- */
37
- clientId: string;
38
- /**
39
- * A valid URL to redirect to after a user authorizes your application. Can be set on [ArcGIS for Developers](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/#registering-your-application),
40
- * [ArcGIS Online](http://doc.arcgis.com/en/arcgis-online/share-maps/add-items.htm#ESRI_SECTION1_0D1B620254F745AE84F394289F8AF44B) or on your instance of ArcGIS Enterprise.
41
- */
42
- redirectUri: string;
43
- /**
44
- * The ArcGIS Online or ArcGIS Enterprise portal you want to use for authentication. Defaults to `https://www.arcgis.com/sharing/rest` for the ArcGIS Online portal.
45
- */
46
- portal?: string;
47
- /**
48
- * ArcGIS Authentication is used by default. Specifying an alternative will take users directly to the corresponding provider's OAuth page.
49
- */
50
- provider?: AuthenticationProvider;
51
- /**
52
- * The requested validity in minutes for a token. Defaults to 20160 (two weeks).
53
- */
54
- expiration?: number;
55
- /**
56
- * Duration (in minutes) that a token will be valid. Defaults to 20160 (two weeks).
57
- *
58
- * @deprecated use 'expiration' instead
59
- */
60
- duration?: number;
61
- /**
62
- * Determines whether to open the authorization window in a new tab/window or in the current window.
63
- *
64
- * @browserOnly
65
- */
66
- popup?: boolean;
67
- /**
68
- * The window features passed to [window.open()](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) when `popup` is true. Defaults to `height=400,width=600,menubar=no,location=yes,resizable=yes,scrollbars=yes,status=yes`
69
- *
70
- * @browserOnly
71
- */
72
- popupWindowFeatures?: string;
73
- /**
74
- * Duration (in minutes) that a refresh token will be valid.
75
- *
76
- * @nodeOnly
77
- */
78
- refreshTokenTTL?: number;
79
- /**
80
- * The locale assumed to render the login page.
81
- *
82
- * @browserOnly
83
- */
84
- locale?: string;
85
- /**
86
- * Applications can specify an opaque value for this parameter to correlate the authorization request sent with the received response. By default, clientId is used.
87
- *
88
- * @browserOnly
89
- */
90
- state?: string;
91
- [key: string]: any;
92
- }
93
- /**
94
- * Options for the `UserSession` constructor.
95
- */
96
- export interface IUserSessionOptions {
97
- /**
98
- * Client ID of your application. Can be obtained by registering an application
99
- * on [ArcGIS for Developers](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/#registering-your-application),
100
- * [ArcGIS Online](http://doc.arcgis.com/en/arcgis-online/share-maps/add-items.htm#ESRI_SECTION1_0D1B620254F745AE84F394289F8AF44B) or on your instance of ArcGIS Enterprise.
101
- */
102
- clientId?: string;
103
- /**
104
- * A valid URL to redirect to after a user authorizes your application. Can be set on [ArcGIS for Developers](https://developers.arcgis.com/documentation/core-concepts/security-and-authentication/signing-in-arcgis-online-users/#registering-your-application),
105
- * [ArcGIS Online](http://doc.arcgis.com/en/arcgis-online/share-maps/add-items.htm#ESRI_SECTION1_0D1B620254F745AE84F394289F8AF44B) or on your instance of ArcGIS Enterprise.
106
- */
107
- redirectUri?: string;
108
- /**
109
- * OAuth 2.0 refresh token from a previous user session.
110
- */
111
- refreshToken?: string;
112
- /**
113
- * Expiration date of the `refreshToken`
114
- */
115
- refreshTokenExpires?: Date;
116
- /**
117
- * The authenticated user's username. Guaranteed to be unique across ArcGIS Online or your instance of ArcGIS Enterprise.
118
- */
119
- username?: string;
120
- /**
121
- * Password for this user. Used in CLI apps where users cannot do OAuth 2.0.
122
- */
123
- password?: string;
124
- /**
125
- * OAuth 2.0 access token from a previous user session.
126
- */
127
- token?: string;
128
- /**
129
- * Expiration date for the `token`
130
- */
131
- tokenExpires?: Date;
132
- /**
133
- * The ArcGIS Online or ArcGIS Enterprise portal you want to use for authentication. Defaults to `https://www.arcgis.com/sharing/rest` for the ArcGIS Online portal.
134
- */
135
- portal?: string;
136
- /**
137
- * This value is set to true automatically if the ArcGIS Organization requires that requests be made over https.
138
- */
139
- ssl?: boolean;
140
- /**
141
- * ArcGIS Authentication is used by default. Specifying an alternative will take users directly to the corresponding provider's OAuth page.
142
- */
143
- provider?: AuthenticationProvider;
144
- /**
145
- * Duration of requested token validity in minutes. Used when requesting tokens with `username` and `password` or when validating the identity of unknown servers. Defaults to two weeks.
146
- */
147
- tokenDuration?: number;
148
- /**
149
- * Duration (in minutes) that a refresh token will be valid.
150
- */
151
- refreshTokenTTL?: number;
152
- /**
153
- * An unfederated ArcGIS Server instance known to recognize credentials supplied manually.
154
- * ```js
155
- * {
156
- * server: "https://sampleserver6.arcgisonline.com/arcgis",
157
- * token: "SOSlV3v..",
158
- * tokenExpires: new Date(1545415669763)
159
- * }
160
- * ```
161
- */
162
- server?: string;
163
- }
164
- /**
165
- * ```js
166
- * import { UserSession } from '@esri/arcgis-rest-auth';
167
- * UserSession.beginOAuth2({
168
- * // register an app of your own to create a unique clientId
169
- * clientId: "abc123",
170
- * redirectUri: 'https://yourapp.com/authenticate.html'
171
- * })
172
- * .then(session)
173
- * // or
174
- * new UserSession({
175
- * username: "jsmith",
176
- * password: "123456"
177
- * })
178
- * // or
179
- * UserSession.deserialize(cache)
180
- * ```
181
- * Used to authenticate both ArcGIS Online and ArcGIS Enterprise users. `UserSession` includes helper methods for [OAuth 2.0](/arcgis-rest-js/guides/browser-authentication/) in both browser and server applications.
182
- */
183
- export declare class UserSession implements IAuthenticationManager {
184
- /**
185
- * The current ArcGIS Online or ArcGIS Enterprise `token`.
186
- */
187
- get token(): string;
188
- /**
189
- * The expiration time of the current `token`.
190
- */
191
- get tokenExpires(): Date;
192
- /**
193
- * The current token to ArcGIS Online or ArcGIS Enterprise.
194
- */
195
- get refreshToken(): string;
196
- /**
197
- * The expiration time of the current `refreshToken`.
198
- */
199
- get refreshTokenExpires(): Date;
200
- /**
201
- * Deprecated, use `federatedServers` instead.
202
- *
203
- * @deprecated
204
- */
205
- get trustedServers(): {
206
- [key: string]: {
207
- token: string;
208
- expires: Date;
209
- };
210
- };
211
- /**
212
- * Begins a new browser-based OAuth 2.0 sign in. If `options.popup` is `true` the
213
- * authentication window will open in a new tab/window and the function will return
214
- * Promise&lt;UserSession&gt;. Otherwise, the user will be redirected to the
215
- * authorization page in their current tab/window and the function will return `undefined`.
216
- *
217
- * @browserOnly
218
- */
219
- static beginOAuth2(options: IOAuth2Options, win?: any): Promise<UserSession> | undefined;
220
- /**
221
- * Completes a browser-based OAuth 2.0 sign in. If `options.popup` is `true` the user
222
- * will be returned to the previous window. Otherwise a new `UserSession`
223
- * will be returned. You must pass the same values for `options.popup` and
224
- * `options.portal` as you used in `beginOAuth2()`.
225
- *
226
- * @browserOnly
227
- */
228
- static completeOAuth2(options: IOAuth2Options, win?: any): UserSession;
229
- /**
230
- * Request session information from the parent application
231
- *
232
- * When an application is embedded into another application via an IFrame, the embedded app can
233
- * use `window.postMessage` to request credentials from the host application. This function wraps
234
- * that behavior.
235
- *
236
- * The ArcGIS API for Javascript has this built into the Identity Manager as of the 4.19 release.
237
- *
238
- * Note: The parent application will not respond if the embedded app's origin is not:
239
- * - the same origin as the parent or *.arcgis.com (JSAPI)
240
- * - in the list of valid child origins (REST-JS)
241
- *
242
- *
243
- * @param parentOrigin origin of the parent frame. Passed into the embedded application as `parentOrigin` query param
244
- * @browserOnly
245
- */
246
- static fromParent(parentOrigin: string, win?: any): Promise<any>;
247
- /**
248
- * Begins a new server-based OAuth 2.0 sign in. This will redirect the user to
249
- * the ArcGIS Online or ArcGIS Enterprise authorization page.
250
- *
251
- * @nodeOnly
252
- */
253
- static authorize(options: IOAuth2Options, response: http.ServerResponse): void;
254
- /**
255
- * Completes the server-based OAuth 2.0 sign in process by exchanging the `authorizationCode`
256
- * for a `access_token`.
257
- *
258
- * @nodeOnly
259
- */
260
- static exchangeAuthorizationCode(options: IOAuth2Options, authorizationCode: string): Promise<UserSession>;
261
- static deserialize(str: string): UserSession;
262
- /**
263
- * Translates authentication from the format used in the [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/).
264
- *
265
- * ```js
266
- * UserSession.fromCredential({
267
- * userId: "jsmith",
268
- * token: "secret"
269
- * });
270
- * ```
271
- *
272
- * @returns UserSession
273
- */
274
- static fromCredential(credential: ICredential): UserSession;
275
- /**
276
- * Handle the response from the parent
277
- * @param event DOM Event
278
- */
279
- private static parentMessageHandler;
280
- /**
281
- * Client ID being used for authentication if provided in the `constructor`.
282
- */
283
- readonly clientId: string;
284
- /**
285
- * The currently authenticated user if provided in the `constructor`.
286
- */
287
- readonly username: string;
288
- /**
289
- * The currently authenticated user's password if provided in the `constructor`.
290
- */
291
- readonly password: string;
292
- /**
293
- * The current portal the user is authenticated with.
294
- */
295
- readonly portal: string;
296
- /**
297
- * This value is set to true automatically if the ArcGIS Organization requires that requests be made over https.
298
- */
299
- readonly ssl: boolean;
300
- /**
301
- * The authentication provider to use.
302
- */
303
- readonly provider: AuthenticationProvider;
304
- /**
305
- * Determines how long new tokens requested are valid.
306
- */
307
- readonly tokenDuration: number;
308
- /**
309
- * A valid redirect URI for this application if provided in the `constructor`.
310
- */
311
- readonly redirectUri: string;
312
- /**
313
- * Duration of new OAuth 2.0 refresh token validity (in minutes).
314
- */
315
- readonly refreshTokenTTL: number;
316
- /**
317
- * An unfederated ArcGIS Server instance known to recognize credentials supplied manually.
318
- * ```js
319
- * {
320
- * server: "https://sampleserver6.arcgisonline.com/arcgis",
321
- * token: "SOSlV3v..",
322
- * tokenExpires: new Date(1545415669763)
323
- * }
324
- * ```
325
- */
326
- readonly server: string;
327
- /**
328
- * Hydrated by a call to [getUser()](#getUser-summary).
329
- */
330
- private _user;
331
- /**
332
- * Hydrated by a call to [getPortal()](#getPortal-summary).
333
- */
334
- private _portalInfo;
335
- private _token;
336
- private _tokenExpires;
337
- private _refreshToken;
338
- private _refreshTokenExpires;
339
- private _pendingUserRequest;
340
- private _pendingPortalRequest;
341
- /**
342
- * Internal object to keep track of pending token requests. Used to prevent
343
- * duplicate token requests.
344
- */
345
- private _pendingTokenRequests;
346
- /**
347
- * Internal list of tokens to 3rd party servers (federated servers) that have
348
- * been created via `generateToken`. The object key is the root URL of the server.
349
- */
350
- private federatedServers;
351
- /**
352
- * Internal list of 3rd party domains that should receive all cookies (credentials: "include").
353
- * Used to for PKI and IWA workflows in high security environments.
354
- */
355
- private trustedDomains;
356
- private _hostHandler;
357
- constructor(options: IUserSessionOptions);
358
- /**
359
- * Returns authentication in a format useable in the [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/).
360
- *
361
- * ```js
362
- * esriId.registerToken(session.toCredential());
363
- * ```
364
- *
365
- * @returns ICredential
366
- */
367
- toCredential(): ICredential;
368
- /**
369
- * Returns information about the currently logged in [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm). Subsequent calls will *not* result in additional web traffic.
370
- *
371
- * ```js
372
- * session.getUser()
373
- * .then(response => {
374
- * console.log(response.role); // "org_admin"
375
- * })
376
- * ```
377
- *
378
- * @param requestOptions - Options for the request. NOTE: `rawResponse` is not supported by this operation.
379
- * @returns A Promise that will resolve with the data from the response.
380
- */
381
- getUser(requestOptions?: IRequestOptions): Promise<IUser>;
382
- /**
383
- * Returns information about the currently logged in user's [portal](https://developers.arcgis.com/rest/users-groups-and-items/portal-self.htm). Subsequent calls will *not* result in additional web traffic.
384
- *
385
- * ```js
386
- * session.getPortal()
387
- * .then(response => {
388
- * console.log(portal.name); // "City of ..."
389
- * })
390
- * ```
391
- *
392
- * @param requestOptions - Options for the request. NOTE: `rawResponse` is not supported by this operation.
393
- * @returns A Promise that will resolve with the data from the response.
394
- */
395
- getPortal(requestOptions?: IRequestOptions): Promise<any>;
396
- /**
397
- * Returns the username for the currently logged in [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm). Subsequent calls will *not* result in additional web traffic. This is also used internally when a username is required for some requests but is not present in the options.
398
- *
399
- * * ```js
400
- * session.getUsername()
401
- * .then(response => {
402
- * console.log(response); // "casey_jones"
403
- * })
404
- * ```
405
- */
406
- getUsername(): Promise<string>;
407
- /**
408
- * Gets an appropriate token for the given URL. If `portal` is ArcGIS Online and
409
- * the request is to an ArcGIS Online domain `token` will be used. If the request
410
- * is to the current `portal` the current `token` will also be used. However if
411
- * the request is to an unknown server we will validate the server with a request
412
- * to our current `portal`.
413
- */
414
- getToken(url: string, requestOptions?: ITokenRequestOptions): Promise<string>;
415
- /**
416
- * Get application access information for the current user
417
- * see `validateAppAccess` function for details
418
- *
419
- * @param clientId application client id
420
- */
421
- validateAppAccess(clientId: string): Promise<IAppAccess>;
422
- toJSON(): IUserSessionOptions;
423
- serialize(): string;
424
- /**
425
- * For a "Host" app that embeds other platform apps via iframes, after authenticating the user
426
- * and creating a UserSession, the app can then enable "post message" style authentication by calling
427
- * this method.
428
- *
429
- * Internally this adds an event listener on window for the `message` event
430
- *
431
- * @param validChildOrigins Array of origins that are allowed to request authentication from the host app
432
- */
433
- enablePostMessageAuth(validChildOrigins: string[], win?: any): any;
434
- /**
435
- * For a "Host" app that has embedded other platform apps via iframes, when the host needs
436
- * to transition routes, it should call `UserSession.disablePostMessageAuth()` to remove
437
- * the event listener and prevent memory leaks
438
- */
439
- disablePostMessageAuth(win?: any): void;
440
- /**
441
- * Manually refreshes the current `token` and `tokenExpires`.
442
- */
443
- refreshSession(requestOptions?: ITokenRequestOptions): Promise<UserSession>;
444
- /**
445
- * Determines the root of the ArcGIS Server or Portal for a given URL.
446
- *
447
- * @param url the URl to determine the root url for.
448
- */
449
- getServerRootUrl(url: string): string;
450
- /**
451
- * Returns the proper [`credentials`] option for `fetch` for a given domain.
452
- * See [trusted server](https://enterprise.arcgis.com/en/portal/latest/administer/windows/configure-security.htm#ESRI_SECTION1_70CC159B3540440AB325BE5D89DBE94A).
453
- * Used internally by underlying request methods to add support for specific security considerations.
454
- *
455
- * @param url The url of the request
456
- * @returns "include" or "same-origin"
457
- */
458
- getDomainCredentials(url: string): RequestCredentials;
459
- /**
460
- * Return a function that closes over the validOrigins array and
461
- * can be used as an event handler for the `message` event
462
- *
463
- * @param validOrigins Array of valid origins
464
- */
465
- private createPostMessageHandler;
466
- /**
467
- * Validates that a given URL is properly federated with our current `portal`.
468
- * Attempts to use the internal `federatedServers` cache first.
469
- */
470
- private getTokenForServer;
471
- /**
472
- * Returns an unexpired token for the current `portal`.
473
- */
474
- private getFreshToken;
475
- /**
476
- * Refreshes the current `token` and `tokenExpires` with `username` and
477
- * `password`.
478
- */
479
- private refreshWithUsernameAndPassword;
480
- /**
481
- * Refreshes the current `token` and `tokenExpires` with `refreshToken`.
482
- */
483
- private refreshWithRefreshToken;
484
- /**
485
- * Exchanges an unexpired `refreshToken` for a new one, also updates `token` and
486
- * `tokenExpires`.
487
- */
488
- private refreshRefreshToken;
489
- /**
490
- * ensures that the authorizedCrossOriginDomains are obtained from the portal and cached
491
- * so we can check them later.
492
- *
493
- * @returns this
494
- */
495
- private fetchAuthorizedDomains;
496
- }