@auth0/auth0-spa-js 2.17.1 → 2.18.0
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.
- package/README.md +1 -1
- package/dist/auth0-spa-js.development.js +57 -38
- package/dist/auth0-spa-js.development.js.map +1 -1
- package/dist/auth0-spa-js.production.esm.js +1 -1
- package/dist/auth0-spa-js.production.esm.js.map +1 -1
- package/dist/auth0-spa-js.production.js +1 -1
- package/dist/auth0-spa-js.production.js.map +1 -1
- package/dist/auth0-spa-js.worker.development.js.map +1 -1
- package/dist/auth0-spa-js.worker.production.js.map +1 -1
- package/dist/lib/auth0-spa-js.cjs.js +57 -38
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +24 -0
- package/dist/typings/global.d.ts +42 -0
- package/dist/typings/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/Auth0Client.ts +57 -2
- package/src/global.ts +44 -0
- package/src/utils.ts +9 -4
- package/src/version.ts +1 -1
|
@@ -58,6 +58,30 @@ export declare class Auth0Client {
|
|
|
58
58
|
private _authorizeUrl;
|
|
59
59
|
private _verifyIdToken;
|
|
60
60
|
private _processOrgHint;
|
|
61
|
+
/**
|
|
62
|
+
* Extracts the session transfer token from the current URL query parameters
|
|
63
|
+
* for Native to Web SSO flows.
|
|
64
|
+
*
|
|
65
|
+
* @param paramName The query parameter name to extract from the URL
|
|
66
|
+
* @returns The session transfer token if present, undefined otherwise
|
|
67
|
+
*/
|
|
68
|
+
private _extractSessionTransferToken;
|
|
69
|
+
/**
|
|
70
|
+
* Clears the session transfer token from the current URL using the History API.
|
|
71
|
+
* This prevents the token from being re-sent on subsequent authentication requests,
|
|
72
|
+
* which is important since session transfer tokens are typically single-use.
|
|
73
|
+
*
|
|
74
|
+
* @param paramName The query parameter name to remove from the URL
|
|
75
|
+
*/
|
|
76
|
+
private _clearSessionTransferTokenFromUrl;
|
|
77
|
+
/**
|
|
78
|
+
* Applies the session transfer token from the URL to the authorization parameters
|
|
79
|
+
* if configured and not already provided.
|
|
80
|
+
*
|
|
81
|
+
* @param authorizationParams The authorization parameters to enhance
|
|
82
|
+
* @returns The authorization parameters with session_transfer_token added if applicable
|
|
83
|
+
*/
|
|
84
|
+
private _applySessionTransferToken;
|
|
61
85
|
private _prepareAuthorizeUrl;
|
|
62
86
|
/**
|
|
63
87
|
* ```js
|
package/dist/typings/global.d.ts
CHANGED
|
@@ -97,6 +97,14 @@ export interface AuthorizationParams {
|
|
|
97
97
|
* methods that provide authentication.
|
|
98
98
|
*/
|
|
99
99
|
redirect_uri?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Session transfer token from a native application for Native to Web SSO.
|
|
102
|
+
* When `sessionTransferTokenQueryParamName` is set, this is automatically
|
|
103
|
+
* extracted from the specified URL query parameter if present.
|
|
104
|
+
*
|
|
105
|
+
* @see https://auth0.com/docs/authenticate/single-sign-on/native-to-web
|
|
106
|
+
*/
|
|
107
|
+
session_transfer_token?: string;
|
|
100
108
|
/**
|
|
101
109
|
* If you need to send custom parameters to the Authorization Server,
|
|
102
110
|
* make sure to use the original parameter name.
|
|
@@ -288,6 +296,40 @@ export interface Auth0ClientOptions {
|
|
|
288
296
|
* defined by Auth0 or custom parameters that you define.
|
|
289
297
|
*/
|
|
290
298
|
authorizationParams?: ClientAuthorizationParams;
|
|
299
|
+
/**
|
|
300
|
+
* Query parameter name to extract the session transfer token from for Native to Web SSO.
|
|
301
|
+
*
|
|
302
|
+
* When set, the SDK automatically extracts the token from the specified URL query
|
|
303
|
+
* parameter and includes it as `session_transfer_token` in authorization requests.
|
|
304
|
+
* This enables seamless single sign-on when users transition from a native mobile
|
|
305
|
+
* application to a web application.
|
|
306
|
+
*
|
|
307
|
+
* After extraction, the token is automatically removed from the URL using
|
|
308
|
+
* `window.history.replaceState()` to prevent accidental reuse on subsequent
|
|
309
|
+
* authentication requests.
|
|
310
|
+
*
|
|
311
|
+
* **Default:** `undefined` (feature disabled)
|
|
312
|
+
*
|
|
313
|
+
* **Common values:**
|
|
314
|
+
* - `'session_transfer_token'` - Standard parameter name
|
|
315
|
+
* - `'stt'` - Shortened version
|
|
316
|
+
* - Custom parameter name of your choice
|
|
317
|
+
*
|
|
318
|
+
* Set to `undefined` to disable automatic extraction if you prefer to handle
|
|
319
|
+
* session transfer tokens manually.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```js
|
|
323
|
+
* const auth0 = await createAuth0Client({
|
|
324
|
+
* domain: '<AUTH0_DOMAIN>',
|
|
325
|
+
* clientId: '<AUTH0_CLIENT_ID>',
|
|
326
|
+
* sessionTransferTokenQueryParamName: 'session_transfer_token'
|
|
327
|
+
* });
|
|
328
|
+
* ```
|
|
329
|
+
*
|
|
330
|
+
* @see https://auth0.com/docs/authenticate/single-sign-on/native-to-web
|
|
331
|
+
*/
|
|
332
|
+
sessionTransferTokenQueryParamName?: string;
|
|
291
333
|
}
|
|
292
334
|
/**
|
|
293
335
|
* Configuration details exposed by the Auth0Client after initialization.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "2.
|
|
1
|
+
declare const _default: "2.18.0";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@auth0/auth0-spa-js",
|
|
4
4
|
"description": "Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.18.0",
|
|
7
7
|
"main": "dist/lib/auth0-spa-js.cjs.js",
|
|
8
8
|
"types": "dist/typings/index.d.ts",
|
|
9
9
|
"module": "dist/auth0-spa-js.production.esm.js",
|
package/src/Auth0Client.ts
CHANGED
|
@@ -378,6 +378,57 @@ export class Auth0Client {
|
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
+
/**
|
|
382
|
+
* Extracts the session transfer token from the current URL query parameters
|
|
383
|
+
* for Native to Web SSO flows.
|
|
384
|
+
*
|
|
385
|
+
* @param paramName The query parameter name to extract from the URL
|
|
386
|
+
* @returns The session transfer token if present, undefined otherwise
|
|
387
|
+
*/
|
|
388
|
+
private _extractSessionTransferToken(paramName: string): string | undefined {
|
|
389
|
+
const params = new URLSearchParams(window.location.search);
|
|
390
|
+
return params.get(paramName) || undefined;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Clears the session transfer token from the current URL using the History API.
|
|
395
|
+
* This prevents the token from being re-sent on subsequent authentication requests,
|
|
396
|
+
* which is important since session transfer tokens are typically single-use.
|
|
397
|
+
*
|
|
398
|
+
* @param paramName The query parameter name to remove from the URL
|
|
399
|
+
*/
|
|
400
|
+
private _clearSessionTransferTokenFromUrl(paramName: string): void {
|
|
401
|
+
try {
|
|
402
|
+
const url = new URL(window.location.href);
|
|
403
|
+
if (url.searchParams.has(paramName)) {
|
|
404
|
+
url.searchParams.delete(paramName);
|
|
405
|
+
window.history.replaceState({}, '', url.toString());
|
|
406
|
+
}
|
|
407
|
+
} catch {
|
|
408
|
+
// Silently fail if URL manipulation isn't possible
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Applies the session transfer token from the URL to the authorization parameters
|
|
414
|
+
* if configured and not already provided.
|
|
415
|
+
*
|
|
416
|
+
* @param authorizationParams The authorization parameters to enhance
|
|
417
|
+
* @returns The authorization parameters with session_transfer_token added if applicable
|
|
418
|
+
*/
|
|
419
|
+
private _applySessionTransferToken(
|
|
420
|
+
authorizationParams: AuthorizationParams
|
|
421
|
+
): AuthorizationParams {
|
|
422
|
+
const paramName = this.options.sessionTransferTokenQueryParamName;
|
|
423
|
+
if (!paramName || authorizationParams.session_transfer_token) {
|
|
424
|
+
return authorizationParams;
|
|
425
|
+
}
|
|
426
|
+
const token = this._extractSessionTransferToken(paramName);
|
|
427
|
+
if (!token) return authorizationParams;
|
|
428
|
+
this._clearSessionTransferTokenFromUrl(paramName);
|
|
429
|
+
return { ...authorizationParams, session_transfer_token: token };
|
|
430
|
+
}
|
|
431
|
+
|
|
381
432
|
private async _prepareAuthorizeUrl(
|
|
382
433
|
authorizationParams: AuthorizationParams,
|
|
383
434
|
authorizeOptions?: Partial<AuthorizeOptions>,
|
|
@@ -463,8 +514,10 @@ export class Auth0Client {
|
|
|
463
514
|
}
|
|
464
515
|
}
|
|
465
516
|
|
|
517
|
+
const authorizationParams = this._applySessionTransferToken(options.authorizationParams || {});
|
|
518
|
+
|
|
466
519
|
const params = await this._prepareAuthorizeUrl(
|
|
467
|
-
|
|
520
|
+
authorizationParams,
|
|
468
521
|
{ response_mode: 'web_message' },
|
|
469
522
|
window.location.origin
|
|
470
523
|
);
|
|
@@ -553,8 +606,10 @@ export class Auth0Client {
|
|
|
553
606
|
urlOptions.authorizationParams?.organization ||
|
|
554
607
|
this.options.authorizationParams.organization;
|
|
555
608
|
|
|
609
|
+
const authorizationParams = this._applySessionTransferToken(urlOptions.authorizationParams || {});
|
|
610
|
+
|
|
556
611
|
const { url, ...transaction } = await this._prepareAuthorizeUrl(
|
|
557
|
-
|
|
612
|
+
authorizationParams
|
|
558
613
|
);
|
|
559
614
|
|
|
560
615
|
this.transactionManager.create<LoginTransaction>({
|
package/src/global.ts
CHANGED
|
@@ -113,6 +113,15 @@ export interface AuthorizationParams {
|
|
|
113
113
|
*/
|
|
114
114
|
redirect_uri?: string;
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Session transfer token from a native application for Native to Web SSO.
|
|
118
|
+
* When `sessionTransferTokenQueryParamName` is set, this is automatically
|
|
119
|
+
* extracted from the specified URL query parameter if present.
|
|
120
|
+
*
|
|
121
|
+
* @see https://auth0.com/docs/authenticate/single-sign-on/native-to-web
|
|
122
|
+
*/
|
|
123
|
+
session_transfer_token?: string;
|
|
124
|
+
|
|
116
125
|
/**
|
|
117
126
|
* If you need to send custom parameters to the Authorization Server,
|
|
118
127
|
* make sure to use the original parameter name.
|
|
@@ -324,6 +333,41 @@ export interface Auth0ClientOptions {
|
|
|
324
333
|
* defined by Auth0 or custom parameters that you define.
|
|
325
334
|
*/
|
|
326
335
|
authorizationParams?: ClientAuthorizationParams;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Query parameter name to extract the session transfer token from for Native to Web SSO.
|
|
339
|
+
*
|
|
340
|
+
* When set, the SDK automatically extracts the token from the specified URL query
|
|
341
|
+
* parameter and includes it as `session_transfer_token` in authorization requests.
|
|
342
|
+
* This enables seamless single sign-on when users transition from a native mobile
|
|
343
|
+
* application to a web application.
|
|
344
|
+
*
|
|
345
|
+
* After extraction, the token is automatically removed from the URL using
|
|
346
|
+
* `window.history.replaceState()` to prevent accidental reuse on subsequent
|
|
347
|
+
* authentication requests.
|
|
348
|
+
*
|
|
349
|
+
* **Default:** `undefined` (feature disabled)
|
|
350
|
+
*
|
|
351
|
+
* **Common values:**
|
|
352
|
+
* - `'session_transfer_token'` - Standard parameter name
|
|
353
|
+
* - `'stt'` - Shortened version
|
|
354
|
+
* - Custom parameter name of your choice
|
|
355
|
+
*
|
|
356
|
+
* Set to `undefined` to disable automatic extraction if you prefer to handle
|
|
357
|
+
* session transfer tokens manually.
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```js
|
|
361
|
+
* const auth0 = await createAuth0Client({
|
|
362
|
+
* domain: '<AUTH0_DOMAIN>',
|
|
363
|
+
* clientId: '<AUTH0_CLIENT_ID>',
|
|
364
|
+
* sessionTransferTokenQueryParamName: 'session_transfer_token'
|
|
365
|
+
* });
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @see https://auth0.com/docs/authenticate/single-sign-on/native-to-web
|
|
369
|
+
*/
|
|
370
|
+
sessionTransferTokenQueryParamName?: string;
|
|
327
371
|
}
|
|
328
372
|
|
|
329
373
|
/**
|
package/src/utils.ts
CHANGED
|
@@ -149,11 +149,16 @@ export const getCrypto = () => {
|
|
|
149
149
|
export const createRandomString = () => {
|
|
150
150
|
const charset =
|
|
151
151
|
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.';
|
|
152
|
+
const validMax = 256 - (256 % charset.length);
|
|
152
153
|
let random = '';
|
|
153
|
-
|
|
154
|
-
getCrypto().getRandomValues(new Uint8Array(43))
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
while (random.length < 43) {
|
|
155
|
+
const bytes = getCrypto().getRandomValues(new Uint8Array(43 - random.length));
|
|
156
|
+
for (const byte of bytes) {
|
|
157
|
+
if (random.length < 43 && byte < validMax) {
|
|
158
|
+
random += charset[byte % charset.length];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
157
162
|
return random;
|
|
158
163
|
};
|
|
159
164
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '2.
|
|
1
|
+
export default '2.18.0';
|