AWS has a lot of great services, but one of the most useful is also one of the least sexy: a basic user management service called Cognito. Cognito provides authentication for users in the cloud. For those of us used to the Azure world, think Azure B2C but with a less awkward configuration. I actually did a Quick Look post on Cognito in 2019.
Integrating AWS Cognito into .NET applications isn’t particularly difficult, but it takes a few steps to make the integration work. This blog post walks you through the setup.
The first step is to create a Cognito user pool in the AWS console.
Once in the Cognito area of the console, you need to create a new user pool. Click “Manage User Pools”.
Then we need to create a new user pool.
When creating a new user pool, you need to add an App client at the same time. Click “App clients”.
When you create your user pool, you will need to save off the user pool ID, and the app client ID (and secret).
Next, we will create a new .NET Core 5 ASP.NET Web Application. There is a variety of ways to do that. The easiest is just within Visual Studio, but you can also do this using the .NET CLI.
After you create your ASP.NET project, you will need to add AspNetCore Identity.
Then you will need to add these AWS NuGet packages:
One thing nice about Cognito is it integrates as an identity provider within a .NET Core application. Cognito behaves just like a standard identity service. But to use it you must make a few edits to Startup.cs.
After updating Startup.cs, you will need to add some configuration. Remember those client id/secrets in the earlier steps? You need them now.
After you have these steps in place, you can just use standard .NET Identity code to create a new user.
The integration of Cognito with an ASP.NET web application can be made very strong. Cognito is a great standalone service regardless of which ecosystem you’re developing in.