Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication AWS Cognito SRP

I am writing a console POC to demo AWS cognito authentication - App Pool not federated identity, as our API gateway authentication mechanism (not hosted in AWS). This is being written in C#.

I have successfully created a user, confirmed them; but now I need to authenticate to retrieve a JWT that an I can pass around and validate downstream.

The following code

 using (var client = new AmazonCognitoIdentityProviderClient())
            {
               var initAuthRequest = new InitiateAuthRequest();
                   initAuthRequest.AuthParameters.Add("USERNAME", username);
                   initAuthRequest.AuthParameters.Add("PASSWORD", password);
                   initAuthRequest.ClientId = clientId;
                   initAuthRequest.AuthFlow = AuthFlowType.USER_SRP_AUTH;
                   var response = client.InitiateAuth(initAuthRequest);
                   WriteLine("auth ok");
            }

Yields this exception:

An unhandled exception of type 'Amazon.CognitoIdentityProvider.Model.InvalidParameterException' occurred in AWSSDK.Core.dll

Additional information: Missing required parameter SRP_A

I cannot find a way in the dotnet sdk of generating an SRP header, can anyone help?

Thanks KH

like image 828
KnowHoper Avatar asked Dec 18 '25 23:12

KnowHoper


1 Answers

There is actually a new extension class, helping with exactly that. Just search for this NuGet package:

AWSSDK.Extensions.CognitoAuthentication

The GitHub repository can be found here.

Some examples can be found here. The very first code example shows you how to do the SRP-flow.

like image 55
Sven Möhring Avatar answered Dec 21 '25 01:12

Sven Möhring