Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Last active April 27, 2018 10:17
Show Gist options
  • Save guitarrapc/719a13ba709558da1a84e38786c937b4 to your computer and use it in GitHub Desktop.
Save guitarrapc/719a13ba709558da1a84e38786c937b4 to your computer and use it in GitHub Desktop.
Sample code to Sign up Cognito UserPool with C# (not Unity or Xamarin)
using Amazon;
using Amazon.CognitoIdentityProvider.Model;
using System.Threading.Tasks;
public class SignUpCognitoUserPoolSample
{
public async Task SignupCognitoUserIntoUserPoolAsync()
{
// Identify your Cognito UserPool Provider
using(var provider = new Amazon.CognitoIdentityProvider.AmazonCognitoIdentityProviderClient(RegionEndpoint.USEast1))
{
// 2016/6/22 : As there are still bug with SecretHash, do not create UserPool with Client Secret enabled. http://stackoverflow.com/questions/37438879/resolve-unable-to-verify-secret-hash-for-client-in-amazon-cognito-userpools
// Sign up new User into your Cognito User Pool
var signup = await provider.SignUpAsync(new SignUpRequest
{
ClientId = "<YOUR USER POOL APPS CLIENT ID>",
Username = "<YOUR USERNAME TO REGISTER INTO USER POOL>",
Password = "<YOUR USERPASSWORD TO REGISTER INTO USER POOL>",,
UserAttributes = new List<Amazon.CognitoIdentityProvider.Model.AttributeType>
{
// INPUT ANY ATTRIBUTES TO REGISTER
// Must include Email and Phone, if MFA is enabled
new AttributeType
{
Name = "email",
Value = "[email protected]",
},
new AttributeType
{
Name = "phone_number",
Value = "<PHONE NUMBER WITH COUNTRY CODE. ex: +810311111111>",
}
}
});
signup.Dump();
}
}
}
@anildbest83
Copy link

After SignUp, how can i UpdateAttributes of Logged-In user? i can not find userPool.getCurrentUser(); in .Net SDK, then how can i get current user and update his attributes in C#.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment