@@ -73,7 +73,7 @@ public virtual async Task<AuthFlowResponse> StartWithSrpAuthAsync(InitiateSrpAut
7373 if ( srpRequest . IsCustomAuthFlow )
7474 {
7575 initiateRequest . AuthFlow = AuthFlowType . CUSTOM_AUTH ;
76- initiateRequest . AuthParameters . Add ( CognitoConstants . ChlgParamChallengeName , CognitoConstants . ChlgParamSrpA ) ;
76+ initiateRequest . AuthParameters ? . Add ( CognitoConstants . ChlgParamChallengeName , CognitoConstants . ChlgParamSrpA ) ;
7777 }
7878 InitiateAuthResponse initiateResponse = await Provider . InitiateAuthAsync ( initiateRequest , cancellationToken ) . ConfigureAwait ( false ) ;
7979 UpdateUsernameAndSecretHash ( initiateResponse . ChallengeParameters ) ;
@@ -172,6 +172,10 @@ private RespondToAuthChallengeRequest CreateDevicePasswordVerifierAuthRequest(Re
172172 string devicePassword ,
173173 Tuple < BigInteger , BigInteger > tupleAa )
174174 {
175+ if ( challenge == null )
176+ throw new ArgumentNullException ( nameof ( challenge ) , $ "{ nameof ( challenge ) } cannot be null") ;
177+ if ( challenge . ChallengeParameters == null )
178+ throw new ArgumentNullException ( nameof ( challenge . ChallengeParameters ) , $ "{ nameof ( challenge . ChallengeParameters ) } cannot be null") ;
175179 string deviceKey = challenge . ChallengeParameters [ CognitoConstants . ChlgParamDeviceKey ] ;
176180 string username = challenge . ChallengeParameters [ CognitoConstants . ChlgParamUsername ] ;
177181 string secretBlock = challenge . ChallengeParameters [ CognitoConstants . ChlgParamSecretBlock ] ;
@@ -255,7 +259,7 @@ public virtual async Task<AuthFlowResponse> StartWithCustomAuthAsync(InitiateCus
255259 initiateResponse . AuthenticationResult ,
256260 initiateResponse . ChallengeName ,
257261 initiateResponse . ChallengeParameters ,
258- new Dictionary < string , string > ( initiateResponse . ResponseMetadata . Metadata ) ) ;
262+ new Dictionary < string , string > ( initiateResponse . ResponseMetadata . Metadata ?? new Dictionary < string , string > ( ) ) ) ;
259263 }
260264
261265 /// <summary>
@@ -286,8 +290,8 @@ public virtual async Task<AuthFlowResponse> RespondToCustomAuthAsync(RespondToCu
286290 {
287291 ChallengeName = ChallengeNameType . CUSTOM_CHALLENGE ,
288292 ClientId = ClientID ,
289- ChallengeResponses = new Dictionary < string , string > ( customRequest . ChallengeParameters ) ,
290- ClientMetadata = new Dictionary < string , string > ( customRequest . ClientMetadata ) ,
293+ ChallengeResponses = new Dictionary < string , string > ( customRequest . ChallengeParameters ?? new Dictionary < string , string > ( ) ) ,
294+ ClientMetadata = new Dictionary < string , string > ( customRequest . ClientMetadata ?? new Dictionary < string , string > ( ) ) ,
291295 AnalyticsMetadata = customRequest . AnalyticsMetadata ,
292296 Session = customRequest . SessionID
293297 } ;
@@ -300,8 +304,8 @@ public virtual async Task<AuthFlowResponse> RespondToCustomAuthAsync(RespondToCu
300304 return new AuthFlowResponse ( authResponse . Session ,
301305 authResponse . AuthenticationResult ,
302306 authResponse . ChallengeName ,
303- authResponse . ChallengeParameters ,
304- new Dictionary < string , string > ( authResponse . ResponseMetadata . Metadata ) ) ;
307+ authResponse . ChallengeParameters ?? new Dictionary < string , string > ( ) ,
308+ new Dictionary < string , string > ( authResponse . ResponseMetadata . Metadata ?? new Dictionary < string , string > ( ) ) ) ;
305309 }
306310
307311 /// <summary>
@@ -469,8 +473,8 @@ public async Task<AuthFlowResponse> RespondToMfaAuthAsync(RespondToMfaRequest mf
469473 return new AuthFlowResponse ( challengeResponse . Session ,
470474 challengeResponse . AuthenticationResult ,
471475 challengeResponse . ChallengeName ,
472- challengeResponse . ChallengeParameters ,
473- new Dictionary < string , string > ( challengeResponse . ResponseMetadata . Metadata ) ) ;
476+ challengeResponse . ChallengeParameters ?? new Dictionary < string , string > ( ) ,
477+ new Dictionary < string , string > ( challengeResponse . ResponseMetadata . Metadata ?? new Dictionary < string , string > ( ) ) ) ;
474478 }
475479
476480 /// <summary>
@@ -577,8 +581,8 @@ public virtual async Task<AuthFlowResponse> RespondToNewPasswordRequiredAsync(Re
577581 return new AuthFlowResponse ( challengeResponse . Session ,
578582 challengeResponse . AuthenticationResult ,
579583 challengeResponse . ChallengeName ,
580- challengeResponse . ChallengeParameters ,
581- new Dictionary < string , string > ( challengeResponse . ResponseMetadata . Metadata ) ) ;
584+ challengeResponse . ChallengeParameters ?? new Dictionary < string , string > ( ) ,
585+ new Dictionary < string , string > ( challengeResponse . ResponseMetadata . Metadata ?? new Dictionary < string , string > ( ) ) ) ;
582586 }
583587
584588 /// <summary>
@@ -617,8 +621,8 @@ public virtual async Task<AuthFlowResponse> StartWithRefreshTokenAuthAsync(Initi
617621 return new AuthFlowResponse ( initiateResponse . Session ,
618622 initiateResponse . AuthenticationResult ,
619623 initiateResponse . ChallengeName ,
620- initiateResponse . ChallengeParameters ,
621- new Dictionary < string , string > ( initiateResponse . ResponseMetadata . Metadata ) ) ;
624+ initiateResponse . ChallengeParameters ?? new Dictionary < string , string > ( ) ,
625+ new Dictionary < string , string > ( initiateResponse . ResponseMetadata . Metadata ?? new Dictionary < string , string > ( ) ) ) ;
622626 }
623627
624628 /// <summary>
@@ -653,8 +657,8 @@ public virtual async Task<AuthFlowResponse> StartWithAdminNoSrpAuthAsync(Initiat
653657 return new AuthFlowResponse ( initiateResponse . Session ,
654658 initiateResponse . AuthenticationResult ,
655659 initiateResponse . ChallengeName ,
656- initiateResponse . ChallengeParameters ,
657- new Dictionary < string , string > ( initiateResponse . ResponseMetadata . Metadata ) ) ;
660+ initiateResponse . ChallengeParameters ?? new Dictionary < string , string > ( ) ,
661+ new Dictionary < string , string > ( initiateResponse . ResponseMetadata . Metadata ?? new Dictionary < string , string > ( ) ) ) ;
658662 }
659663
660664 /// <summary>
@@ -715,7 +719,7 @@ private void UpdateUsernameAndSecretHash(IDictionary<string, string> challengePa
715719 return ;
716720 }
717721
718- if ( challengeParameters . ContainsKey ( CognitoConstants . ChlgParamUsername ) )
722+ if ( challengeParamIsUsername )
719723 {
720724 Username = challengeParameters [ CognitoConstants . ChlgParamUsername ] ;
721725 }
@@ -802,6 +806,10 @@ private RespondToAuthChallengeRequest CreateSrpPasswordVerifierAuthRequest(Initi
802806 string password ,
803807 Tuple < BigInteger , BigInteger > tupleAa )
804808 {
809+ if ( challenge == null )
810+ throw new ArgumentNullException ( nameof ( challenge ) , $ "{ nameof ( challenge ) } cannot be null") ;
811+ if ( challenge . ChallengeParameters == null )
812+ throw new ArgumentNullException ( nameof ( challenge . ChallengeParameters ) , $ "{ nameof ( challenge . ChallengeParameters ) } cannot be null") ;
805813 string username = challenge . ChallengeParameters [ CognitoConstants . ChlgParamUsername ] ;
806814 string poolName = PoolName ;
807815 string secretBlock = challenge . ChallengeParameters [ CognitoConstants . ChlgParamSecretBlock ] ;
0 commit comments