Skip to content

Instantly share code, notes, and snippets.

@georgebearden
Last active December 29, 2018 01:58
Show Gist options
  • Save georgebearden/c6c6908cb3e1b81281b3b5b2025a861d to your computer and use it in GitHub Desktop.
Save georgebearden/c6c6908cb3e1b81281b3b5b2025a861d to your computer and use it in GitHub Desktop.

Different ways to get AWS credentials into the Cognito client

public AmazonCognitoIdentityProviderClient CreateFromKeys()
{
  var creds = new BasicAWSCredentials("ACCESS_KEY", "SECRET_KEY");
  return new AmazonCognitoIdentityProviderClient(creds, RegionEndpoint.USEast1);
}

 public AmazonCognitoIdentityProviderClient CreateFromProfile()
 {
  var creds = new SharedCredentialsFile();
  CredentialProfile cognitoProfile;
  if (!creds.TryGetProfile("cognito", out cognitoProfile))
  {
    throw new Exception($"Missing credentials for profile: cognito");
  }

  var keys = new BasicAWSCredentials(cognitoProfile.Options.AccessKey, cognitoProfile.Options.SecretKey);
  return new AmazonCognitoIdentityProviderClient(keys, cognitoProfile.Region);
}

Thoughts on the API

  • SignUp should be a user triggered action, and the result is a verified user after they confirm their email (if that is how the user pool is configured). AdminCreateUser should be an admin triggered action, and adds the step of requiring the invited user to change the password to confirm their account.
  • Not sure why InitiateAuth is not supported for the ADMIN_NO_SRP_AUTH Auth Flow type but for AdminInitiateAuth it is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment