-
-
Save guitarrapc/719a13ba709558da1a84e38786c937b4 to your computer and use it in GitHub Desktop.
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(); | |
} | |
} | |
} |
The error "Unable to store key CognitoIdentity:IdentityId:us-east-1:d8dce20b-7e3a-454a-afe5-xxxxxxxxxxxx, got error: -34018" is gone after adding Entitlements.pist to iOS Bundle Signing option and adding provisioning profile, but now I am getting the error "Cannot Determine Pool". I tried AnonymousAWSCredentials and now the error is different that secret hash could not be verified..
Thank you,
Benny
Hello, anyone knows what is "signup.Dump()" at the end? I have an error which says "signUpResponse does not contain a definition of Dump".
@JYL123 You can remove that line... It sounds like the code was run in LinqPad which has a .Dump() function to dump into the console.
Does anyone know how to port this into C# for Unity? I'm not sure if they've released CognitoIdentityProvider for Unity
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#.
I tried the following code and I am getting an exception when I call "providerClient.SignUpAsync" with a message
"Unable to store key CognitoIdentity:IdentityId:us-east-1:d8dce20b-7e3a-454a-afe5-xxxxxxxxxxxx, got error: -34018". I am not able to find a way to specify the "userpool id" in the code and I am not able to understand what am I doing wrong here. I would really appreciate if anyone can help me here to tell me what am I doing wrong here.
CognitoAWSCredentials credentials = new CognitoAWSCredentials(
"us-east-1:d8dce20b-7e3a-454a-afe5-xxxxxxxxxxxx",
RegionEndpoint.USEast1
);
AmazonCognitoIdentityProviderClient providerClient = new AmazonCognitoIdentityProviderClient(credentials,RegionEndpoint.USEast1);