Last active
April 27, 2018 10:17
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Hey, I've ported the Cognito Identity Provider from the AWS SDK for .NET 4.5, so that you can use it in Unity, using the .NET Framework 2.0:
https://github.com/SolidWhiteSven/amazon-cognito-unity
All the Best,
Sven
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
Does anyone know how to port this into C# for Unity? I'm not sure if they've released CognitoIdentityProvider for Unity