Cognito Basic User Operations in C#

When building a solution on top of Cognito, we will often build on top of the existing Cognito user interface. But, it is possible to make all of the authentication calls without using it in a UI. In this blog post, I’ll show how to use C# to make these calls. You probably should avoid making these calls straight from within C#. Using the existing Cognito UI is typically the better option because it puts more of the security concern within the hands of AWS. The user’s password will never interact directly with our code.

This post assumes you have read my previous blog post, in which I set up a Cognito app with sign-in functionality written in C#.

Let’s start with a user signing up for the first time.

If you create a user, it still might not be verified. You can verify a user using the following code.

What if a user needs to reset a password? You can do that too.

Typically, changing a password can be done in two ways. The first involves just entering your previous password. You can also reset your password using a reset password link that sends you a code to your email address. But here, we will look at the first option, which involves entering your old password. That is what we will look at here. This also requires that you are logged in. You will notice that we have an access token below. Getting an access token is pretty easy. The previous blog post shows how to do that, but I am showing it again here.

Once you have an access token, you can reset your password. This requires you to provide the previous password and your current access token.

I hope the example above helps if you are working with AWS Cognito.

Related posts