@@ -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 > {
0 commit comments