Skip to content

Commit 6ceebed

Browse files
authored
Merge pull request #94 from brionmario/next
fix: `@asgardeo/react-router` issues + expose `signInSilently` from `@asgardeo/react`
2 parents 49770f4 + cb918a3 commit 6ceebed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+355
-822
lines changed

.changeset/tall-lemons-cheat.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@asgardeo/browser': patch
3+
'@asgardeo/javascript': patch
4+
'@asgardeo/nextjs': patch
5+
'@asgardeo/react': patch
6+
'@asgardeo/react-router': patch
7+
'@asgardeo/vue': patch
8+
---
9+
10+
This update addresses issues in the `@asgardeo/react-router` package and exposes the `signInSilently` method from the `@asgardeo/react` package. The changes ensure that the `ProtectedRoute` component works correctly with the new sign-in functionality.

packages/browser/src/__legacy__/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,10 @@ export class AsgardeoSPAClient {
428428
*
429429
* @example
430430
*```
431-
* auth.trySignInSilently()
431+
* auth.signInSilently()
432432
*```
433433
*/
434-
public async trySignInSilently(
434+
public async signInSilently(
435435
additionalParams?: Record<string, string | boolean>,
436436
tokenRequestConfig?: {params: Record<string, unknown>},
437437
): Promise<User | boolean | undefined> {
@@ -442,7 +442,7 @@ export class AsgardeoSPAClient {
442442
return undefined;
443443
}
444444

445-
return this._client?.trySignInSilently(additionalParams, tokenRequestConfig).then((response: User | boolean) => {
445+
return this._client?.signInSilently(additionalParams, tokenRequestConfig).then((response: User | boolean) => {
446446
if (this._onSignInCallback && response) {
447447
this._onSignInCallback(response as User);
448448
}

packages/browser/src/__legacy__/clients/main-thread-client.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ export const MainThreadClient = async (
356356
* @return {Promise<User|boolean} Returns a Promise that resolves with the User
357357
* if the user is signed in or with `false` if there is no active user session in the server.
358358
*/
359-
const trySignInSilently = async (
359+
const signInSilently = async (
360360
additionalParams?: Record<string, string | boolean>,
361361
tokenRequestConfig?: {params: Record<string, unknown>},
362362
): Promise<User | boolean> =>
363-
_authenticationHelper.trySignInSilently(
363+
_authenticationHelper.signInSilently(
364364
constructSilentSignInUrl,
365365
requestAccessToken,
366366
_sessionManagementHelper,
@@ -370,7 +370,8 @@ export const MainThreadClient = async (
370370

371371
const getUser = async (): Promise<User> => _authenticationHelper.getUser();
372372

373-
const getDecodedIdToken = async (sessionId?: string): Promise<IdToken> => _authenticationHelper.getDecodedIdToken(sessionId);
373+
const getDecodedIdToken = async (sessionId?: string): Promise<IdToken> =>
374+
_authenticationHelper.getDecodedIdToken(sessionId);
374375

375376
const getCrypto = async (): Promise<IsomorphicCrypto> => _authenticationHelper.getCrypto();
376377

@@ -437,7 +438,7 @@ export const MainThreadClient = async (
437438
setHttpRequestSuccessCallback,
438439
signIn,
439440
signOut,
440-
trySignInSilently,
441+
signInSilently,
441442
reInitialize,
442443
};
443444
};

packages/browser/src/__legacy__/clients/web-worker-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,11 @@ export const WebWorkerClient = async (
429429
* @return {Promise<User|boolean} Returns a Promise that resolves with the User
430430
* if the user is signed in or with `false` if there is no active user session in the server.
431431
*/
432-
const trySignInSilently = async (
432+
const signInSilently = async (
433433
additionalParams?: Record<string, string | boolean>,
434434
tokenRequestConfig?: {params: Record<string, unknown>},
435435
): Promise<User | boolean> => {
436-
return await _authenticationHelper.trySignInSilently(
436+
return await _authenticationHelper.signInSilently(
437437
constructSilentSignInUrl,
438438
requestAccessToken,
439439
_sessionManagementHelper,
@@ -859,7 +859,7 @@ export const WebWorkerClient = async (
859859
setHttpRequestSuccessCallback,
860860
signIn,
861861
signOut,
862-
trySignInSilently,
862+
signInSilently,
863863
reInitialize,
864864
};
865865
};

packages/browser/src/__legacy__/helpers/authentication-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export class AuthenticationHelper<T extends MainThreadClientConfig | WebWorkerCl
505505
);
506506
}
507507

508-
public async trySignInSilently(
508+
public async signInSilently(
509509
constructSilentSignInUrl: (additionalParams?: Record<string, string | boolean>) => Promise<string>,
510510
requestAccessToken: (
511511
authzCode: string,

packages/browser/src/__legacy__/models/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface MainThreadClientInterface {
6868
getStorageManager(): Promise<StorageManager<MainThreadClientConfig>>;
6969
isSignedIn(): Promise<boolean>;
7070
reInitialize(config: Partial<AuthClientConfig<MainThreadClientConfig>>): Promise<void>;
71-
trySignInSilently(
71+
signInSilently(
7272
additionalParams?: Record<string, string | boolean>,
7373
tokenRequestConfig?: {params: Record<string, unknown>},
7474
): Promise<User | boolean>;
@@ -107,7 +107,7 @@ export interface WebWorkerClientInterface {
107107
setHttpRequestFinishCallback(callback: () => void): void;
108108
refreshAccessToken(): Promise<User>;
109109
reInitialize(config: Partial<AuthClientConfig<WebWorkerClientConfig>>): Promise<void>;
110-
trySignInSilently(
110+
signInSilently(
111111
additionalParams?: Record<string, string | boolean>,
112112
tokenRequestConfig?: {params: Record<string, unknown>},
113113
): Promise<User | boolean>;

packages/javascript/src/AsgardeoJavaScriptClient.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ abstract class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T>
6666
onSignInSuccess?: (afterSignInUrl: string) => void,
6767
): Promise<User>;
6868

69+
abstract signInSilently(options?: SignInOptions): Promise<User | boolean>;
70+
6971
abstract signOut(options?: SignOutOptions, afterSignOut?: (afterSignOutUrl: string) => void): Promise<string>;
7072
abstract signOut(
7173
options?: SignOutOptions,

packages/javascript/src/models/client.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export interface AsgardeoClient<T> {
6363
* @param organization - The organization to switch to.
6464
* @returns A promise that resolves when the switch is complete.
6565
*/
66-
switchOrganization(organization: Organization, sessionId?: string): Promise<TokenResponse | Response> ;
66+
switchOrganization(organization: Organization, sessionId?: string): Promise<TokenResponse | Response>;
6767

6868
getConfiguration(): T;
6969

@@ -137,6 +137,17 @@ export interface AsgardeoClient<T> {
137137
onSignInSuccess?: (afterSignInUrl: string) => void,
138138
): Promise<User>;
139139

140+
/**
141+
* Try signing in silently in the background without any user interactions.
142+
*
143+
* @remarks This approach uses a passive auth request (prompt=none) sent from an iframe which might pose issues in cross-origin scenarios.
144+
* Make sure you are aware of the limitations and browser compatibility issues.
145+
*
146+
* @param options - Optional sign-in options like additional parameters to be sent in the authorize request, etc.
147+
* @returns A promise that resolves to the user if sign-in is successful, or false if not.
148+
*/
149+
signInSilently(options?: SignInOptions): Promise<User | boolean>;
150+
140151
/**
141152
* Signs out the currently signed-in user.
142153
*

packages/nextjs/src/AsgardeoNextClient.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,15 @@ class AsgardeoNextClient<T extends AsgardeoNextConfig = AsgardeoNextConfig> exte
488488
);
489489
}
490490

491+
override signInSilently(options?: SignInOptions): Promise<User | boolean> {
492+
throw new AsgardeoRuntimeError(
493+
'Not implemented',
494+
'AsgardeoNextClient-signInSilently-NotImplementedError-001',
495+
'nextjs',
496+
'The signInSilently method is not implemented in the Next.js client.',
497+
);
498+
}
499+
491500
/**
492501
* Gets the sign-in URL for authentication.
493502
* Ensures the client is initialized before making the call.

0 commit comments

Comments
 (0)