1

I've been scratching my head with this authflow. I'm able to use Cognito's built hosted UI to return the authorization code, but I haven't figure out how to do this programmatically as we are hosting our own UI for the login.

I'm trying to do what the below link does but in c#, where I accept a user name and password and return the authorization code.

https://.auth.us-west-2.amazoncognito.com/oauth2/authorize?client_id=&redirect_uri=https://localhost:5001&scope=openid&response_type=code

I have tried a number of options to get this working, but so far I haven't been able to figure out how to get the authorization code.

AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), RegionEndpoint.USWest2);
var userPool = new CognitoUserPool(_userPool, _clientId, provider, _settings.Value.AppClientSecret);


var user = new CognitoUser(username, _clientId, userPool, provider, _settings.Value.AppClientSecret);

var authRequest = new InitiateSrpAuthRequest()
{
    Password = password
};

try
{
    var authResponse = await user.StartWithSrpAuthAsync(authRequest);

    if (authResponse.ChallengeName == ChallengeNameType.NEW_PASSWORD_REQUIRED)
    {
        throw new Exception("User must change password.");
    }

    var timeSpan = TimeSpan.FromSeconds(authResponse.AuthenticationResult.ExpiresIn);
    var expiry = DateTimeOffset.Now + timeSpan;
}
catch (Exception e)
{
    Console.WriteLine(e);
    throw;
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.