Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing custom params to token request via silent sign-in method #177

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions lib/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ export class AsgardeoSPAClient {
*```
*/
public async trySignInSilently(
additionalParams?: Record<string, string | boolean>
additionalParams?: Record<string, string | boolean>,
tokenRequestConfig?: { params: Record<string, unknown> }
): Promise<BasicUserInfo | boolean | undefined> {
await this._isInitialized();

Expand All @@ -425,21 +426,22 @@ export class AsgardeoSPAClient {
return;
}

return this._client?.trySignInSilently(additionalParams).then((response: BasicUserInfo | boolean) => {
if (this._onSignInCallback && response) {
const basicUserInfo = response as BasicUserInfo;
if (
basicUserInfo.allowedScopes ||
basicUserInfo.displayName ||
basicUserInfo.email ||
basicUserInfo.username
) {
this._onSignInCallback(basicUserInfo);
return this._client?.trySignInSilently(additionalParams, tokenRequestConfig)
.then((response: BasicUserInfo | boolean) => {
if (this._onSignInCallback && response) {
const basicUserInfo = response as BasicUserInfo;
if (
basicUserInfo.allowedScopes ||
basicUserInfo.displayName ||
basicUserInfo.email ||
basicUserInfo.username
) {
this._onSignInCallback(basicUserInfo);
}
}
}

return response;
});
return response;
});
}

/**
Expand Down
6 changes: 4 additions & 2 deletions lib/src/clients/main-thread-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,16 @@ export const MainThreadClient = async (
* if the user is signed in or with `false` if there is no active user session in the server.
*/
const trySignInSilently = async (
additionalParams: Record<string, string | boolean> = {}
additionalParams?: Record<string, string | boolean>,
tokenRequestConfig?: { params: Record<string, unknown> }
): Promise<BasicUserInfo | boolean> => {

return await _authenticationHelper.trySignInSilently(
constructSilentSignInUrl,
requestAccessToken,
_sessionManagementHelper,
additionalParams
additionalParams,
tokenRequestConfig
);
};

Expand Down
6 changes: 4 additions & 2 deletions lib/src/clients/web-worker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,15 @@ export const WebWorkerClient = async (
* if the user is signed in or with `false` if there is no active user session in the server.
*/
const trySignInSilently = async (
additionalParams: Record<string, string | boolean> = {}
additionalParams?: Record<string, string | boolean>,
tokenRequestConfig?: { params: Record<string, unknown> }
): Promise<BasicUserInfo | boolean> => {
return await _authenticationHelper.trySignInSilently(
constructSilentSignInUrl,
requestAccessToken,
_sessionManagementHelper,
additionalParams
additionalParams,
tokenRequestConfig
);
};

Expand Down
9 changes: 6 additions & 3 deletions lib/src/helpers/authentication-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,11 @@ export class AuthenticationHelper<

public async trySignInSilently(
constructSilentSignInUrl: (additionalParams?: Record<string, string | boolean>) => Promise<string>,
requestAccessToken: (authzCode: string, sessionState: string, state: string) => Promise<BasicUserInfo>,
requestAccessToken: (authzCode: string, sessionState: string, state: string,
tokenRequestConfig?: { params: Record<string, unknown> }) => Promise<BasicUserInfo>,
sessionManagementHelper: SessionManagementHelperInterface,
additionalParams?: Record<string, string | boolean>
additionalParams?: Record<string, string | boolean>,
tokenRequestConfig?: { params: Record<string, unknown> }
): Promise<BasicUserInfo | boolean> {

// This block is executed by the iFrame when the server redirects with the authorization code.
Expand Down Expand Up @@ -590,7 +592,8 @@ export class AuthenticationHelper<
}

if (data?.type == CHECK_SESSION_SIGNED_IN && data?.data?.code) {
requestAccessToken(data?.data?.code, data?.data?.sessionState, data?.data?.state)
requestAccessToken(data?.data?.code, data?.data?.sessionState,
data?.data?.state, tokenRequestConfig)
.then((response: BasicUserInfo) => {
window.removeEventListener("message", listenToPromptNoneIFrame);
resolve(response);
Expand Down
7 changes: 5 additions & 2 deletions lib/src/models/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export interface MainThreadClientInterface {
getDataLayer(): Promise<DataLayer<MainThreadClientConfig>>;
isAuthenticated(): Promise<boolean>;
updateConfig(config: Partial<AuthClientConfig<MainThreadClientConfig>>): Promise<void>;
trySignInSilently(additionalParams?: Record<string, string | boolean>): Promise<BasicUserInfo | boolean>;
trySignInSilently(additionalParams?: Record<string, string | boolean>,
tokenRequestConfig?: { params: Record<string, unknown> }
): Promise<BasicUserInfo | boolean>;
isSessionActive(): Promise<boolean>;
}

Expand Down Expand Up @@ -103,5 +105,6 @@ export interface WebWorkerClientInterface {
setHttpRequestFinishCallback(callback: () => void): void;
refreshAccessToken(): Promise<BasicUserInfo>;
updateConfig(config: Partial<AuthClientConfig<WebWorkerClientConfig>>): Promise<void>;
trySignInSilently(additionalParams?: Record<string, string | boolean>): Promise<BasicUserInfo | boolean>;
trySignInSilently(additionalParams?: Record<string, string | boolean>,
tokenRequestConfig?: { params: Record<string, unknown> }): Promise<BasicUserInfo | boolean>;
}
Loading