Skip to content

Commit 9427eef

Browse files
committed
address review comments
1 parent 4807fb9 commit 9427eef

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

packages/javascript/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"dependencies": {
5656
"@asgardeo/i18n": "workspace:*",
5757
"tslib": "2.8.1",
58-
"base64url": "^3.0.1",
5958
"jose": "^5.2.0"
6059
},
6160
"publishConfig": {

packages/javascript/src/AsgardeoJavaScriptClient.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
5555

5656
private baseURL: string;
5757

58-
void: void;
59-
6058
constructor(config?: AuthClientConfig<T>, cacheStore?: Storage, cryptoUtils?: Crypto) {
6159
this.cacheStore = cacheStore ?? new DefaultCacheStore();
6260
this.cryptoUtils = cryptoUtils ?? new DefaultCrypto();
@@ -178,23 +176,23 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
178176
url: `${authorizeURL.origin}${authorizeURL.pathname}`,
179177
});
180178

181-
const usernamePasswordAuthenticator: EmbeddedSignInFlowAuthenticator | undefined =
179+
const authenticatorName: string = agentConfig.authenticatorName ?? AgentConfig.DEFAULT_AUTHENTICATOR_NAME;
180+
181+
const targetAuthenticator: EmbeddedSignInFlowAuthenticator | undefined =
182182
authorizeResponse.nextStep.authenticators.find(
183-
(auth: EmbeddedSignInFlowAuthenticator) => auth.authenticator === 'Username & Password',
183+
(auth: EmbeddedSignInFlowAuthenticator) => auth.authenticator === authenticatorName,
184184
);
185185

186-
if (!usernamePasswordAuthenticator) {
187-
// eslint-disable-next-line no-console
188-
console.error('Basic authenticator not found among authentication steps.');
189-
return Promise.reject(new Error('Basic authenticator not found among authentication steps.'));
186+
if (!targetAuthenticator) {
187+
throw new Error(`Authenticator '${authenticatorName}' not found among authentication steps.`);
190188
}
191189

192190
const authnRequest: EmbeddedFlowExecuteRequestConfig = {
193191
baseUrl: this.baseURL,
194192
payload: {
195193
flowId: authorizeResponse.flowId,
196194
selectedAuthenticator: {
197-
authenticatorId: usernamePasswordAuthenticator.authenticatorId,
195+
authenticatorId: targetAuthenticator.authenticatorId,
198196
params: {
199197
password: agentConfig.agentSecret,
200198
username: agentConfig.agentID,
@@ -206,18 +204,14 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
206204
const authnResponse: EmbeddedSignInFlowHandleResponse = await executeEmbeddedSignInFlow(authnRequest);
207205

208206
if (authnResponse.flowStatus !== EmbeddedSignInFlowStatus.SuccessCompleted) {
209-
// eslint-disable-next-line no-console
210-
console.error('Agent Authentication Failed.');
211-
return Promise.reject(new Error('Agent Authentication Failed.'));
207+
throw new Error('Agent authentication failed.');
212208
}
213209

214-
const tokenResponse: TokenResponse = await this.auth.requestAccessToken(
210+
return this.auth.requestAccessToken(
215211
authnResponse.authData['code'],
216212
authnResponse.authData['session_state'],
217213
authnResponse.authData['state'],
218214
);
219-
220-
return tokenResponse;
221215
}
222216

223217
public async getOBOSignInURL(agentConfig: AgentConfig): Promise<string> {
@@ -228,10 +222,10 @@ class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T> {
228222
const authURL: string | undefined = await this.auth.getSignInUrl(customParam);
229223

230224
if (authURL) {
231-
return Promise.resolve(authURL.toString());
225+
return authURL.toString();
232226
}
233227

234-
return Promise.reject(new Error('Could not build Authorize URL'));
228+
throw new Error('Could not build Authorize URL');
235229
}
236230

237231
public async getOBOToken(agentConfig: AgentConfig, authCodeResponse: AuthCodeResponse): Promise<TokenResponse> {

packages/javascript/src/models/agent.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,19 @@ export interface AgentConfig {
2828
* The secret credential for the agent
2929
*/
3030
agentSecret: string;
31+
/**
32+
* The authenticator name to match during the embedded sign-in flow.
33+
* Defaults to {@link AgentConfig.DEFAULT_AUTHENTICATOR_NAME} if not provided.
34+
*/
35+
authenticatorName?: string;
36+
}
37+
38+
/**
39+
* Namespace that holds constants related to {@link AgentConfig}.
40+
*/
41+
export namespace AgentConfig {
42+
/**
43+
* Default authenticator name used when none is specified.
44+
*/
45+
export const DEFAULT_AUTHENTICATOR_NAME: string = 'Username & Password';
3146
}

0 commit comments

Comments
 (0)