Cognito Archives - ab https://alexandrebruffa.com/tag/cognito/ Wed, 18 Sep 2024 23:34:02 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://alexandrebruffa.com/wp-content/uploads/2022/04/cropped-cropped-elior-favicon-270x270-1-32x32.png Cognito Archives - ab https://alexandrebruffa.com/tag/cognito/ 32 32 Unity3D + Amazon Cognito: My New Course on Udemy! https://alexandrebruffa.com/unity3d-amazon-cognito-my-new-course-on-udemy/ https://alexandrebruffa.com/unity3d-amazon-cognito-my-new-course-on-udemy/#respond Wed, 18 Sep 2024 23:30:25 +0000 https://alexandrebruffa.com/?p=1962 In this post, I will present my new course on Udemy.

The post Unity3D + Amazon Cognito: My New Course on Udemy! appeared first on ab.

]]>
I’m very excited to share with you that I have published my first course on Udemy! 

➡ Check it out: Unity3D + Amazon Cognito: The ultimate guide 2024!

This course focuses on how Unity3D and Amazon Cognito can work together and is divided into two main parts: using Cognito as a user directory and as an authorization service for Unity.

In the first part of the course we will see how Amazon Cognito can be used as a user directory. We will learn how to create, retrieve, and delete users from Unity. I will also show you some advanced features of Cognito such as the hosted UI or the federation endpoints and how to log in to a Cognito user with a Google account.

In the second part of the course, we will use Amazon Cognito as an authorization service. We will access Lambda, S3, and DynamoDB from Unity with guest and authenticated users. We will also see the pros and cons of having a direct integration vs. exposing an endpoint and how Cognito can act as an authorizer to secure an endpoint.

I conceived this course as a practice guide; beyond learning Cognito concepts and features, I will show how to write functional C# code in Unity scripts and how to use the AWS console with different Amazon services.

I really hope you will like it and find it useful for your future personal or professional projects. If you have some feedback or suggestions, please reach out to me on my social networks:

🌳 Alexandre Bruffa

The post Unity3D + Amazon Cognito: My New Course on Udemy! appeared first on ab.

]]>
https://alexandrebruffa.com/unity3d-amazon-cognito-my-new-course-on-udemy/feed/ 0
Signing Up Users From Unity3D to AWS Cognito Using the AWS SDK for .NET https://alexandrebruffa.com/signing-up-users-from-unity3d-to-aws-cognito-using-the-aws-sdk-for-net/ Wed, 22 Mar 2023 05:28:07 +0000 https://alexandrebruffa.com/?p=1727 In this article, I will explain how to register users from Unity3D to AWS Cognito using the AWS SDK for .NET.

The post Signing Up Users From Unity3D to AWS Cognito Using the AWS SDK for .NET appeared first on ab.

]]>
This article was initially published on my Medium Page.

Days ago, I published an article about creating a simple signup flow with Unity3D and AWS Cognito. Some days later, Yan Cui published an excellent article about a passwordless integration with Vue, Amplify, and AWS Cognito. I talked with him later, and he asked me the following:

Out of curiosity, what client did you use for Unity, the C# AWS SDK?

I did not use the AWS SDK for .NET; since integrating Unity and Cognito is relatively simple, I used “Vanilla” Unity. At this point, I started to doubt my own words. Is it easier to use Vanilla Unity over the AWS SDK? Let’s see.

Dealing With the AWS SDK for .NET

Do you remember my article about building a monitoring system? I used there the AWS SDK to integrate Unity and S3. Please refer to it for a detailed explanation of the NuGet mechanism.

For the current integration, we need the AWS core and the AWS Cognito packages. Since the AWS SDK functions use asynchronous tasks, we also need the AsyncInterfaces package.

We download the three packages, unzip them, and place the DLL files in the Plugins folder of our project:

Plugins folder of Unity project

The Code

First of all, we create the Cognito client:

Notes:

  • We use the AmazonCognitoIdentityProviderClient constructor to create a new Cognito client.
  • Since we connect as an anonymous user (without credentials, IAM user, or other), we use the class AnonymousAWSCredentials.
  • We specify the region where the Cognito User Pool has been created (In my case, Ohio).

Then, we create the signup function with the following code:

Notes:

  • The class Task is a pure .NET mechanism to manage asynchronous processes. You can call it in Unity with the await operator within an async function.
  • We add an email attribute to perform an email confirmation.
  • We perform the signup thanks to the SignUpRequest and SignUpAsync classes as specified in the documentation.

And here is the confirm function:

Notes:

Conclusion

Working with the AWS SDK in Unity is complex: you have to install the SDK through the NuGet website, work with .NET asynchronous classes, create a client, deal with the credentials, and check the AWS documentation to implement the functions.

However, working with the AWS SDK is a good practice; it may be a bit tedious for this particular case, but it is a game changer for complex processes like a file upload to S3. Furthermore, almost all the AWS SDK implementations have the same structure (Task -> Request -> Function), making it much easier after successfully performing your first implementation.

Thanks for reading this article. I hope you liked it!

The post Signing Up Users From Unity3D to AWS Cognito Using the AWS SDK for .NET appeared first on ab.

]]>
Building a Simple Signup Flow With Unity3D and AWS Cognito https://alexandrebruffa.com/building-a-simple-signup-flow-with-unity3d-and-aws-cognito/ Sat, 11 Mar 2023 17:26:27 +0000 https://alexandrebruffa.com/?p=1718 In this article, I will explain how to Build a Simple Signup Flow With Unity3D and AWS Cognito for your applications or games.

The post Building a Simple Signup Flow With Unity3D and AWS Cognito appeared first on ab.

]]>
This article was initially published on my Medium Page.

Weeks ago, a nice guy reached out to me on LinkedIn. He told me the following:

Hey, Alexandre, how are you? I’m trying to register users in an AWS Cognito User Pool from a Unity3D app, but I’m struggling to find literature for this. Could you help me to build a simple signup flow?

Oh, this is interesting! I usually receive questions on my social networks, but this one deserves a detailed answer. Let’s see.

If you prefer watching a video instead of reading, please check the following video:

The Cognito Signup Flow

The Cognito documentation tells us the following:

  1. A user first signs up to Cognito. State: Unconfirmed
  2. Then, the signup needs to be confirmed. There are three ways to do it: the user can do it by email or phone, it can be done with an admin function, or it can be done automatically with a Lambda trigger. State: Confirmed.
  3. The user can log in.

User Confirm, Admin Confirm, and Automatic confirm:

This article will detail the signup process and the three ways to confirm it.

Cognito

When you create your User Pool, ensure you have chosen a confirmation method. I can be by email or by SMS. In this article, we will perform an email validation.

Also, activate the self-service sign-up so that the users can signup themselves.

The Signup

Here’s what the signup function in Unity looks like:

Notes:

  • We send the three mandatory attributes specified in the Cognito documentation: the username, the password, and the User Pool application ID.
  • We send the user’s email as a user attribute so that Cognito can send the user an email with a confirmation code.
  • The Post function of UnityWebRequest does not support JSON strings and uses a strange HTML string encryption instead. A workaround is to do a weird trick with a byte array and a Put request. Please let me know if you have a better solution in the comments section.
  • We specify the value AWSCognitoIdentityProviderService.SignUp as a header.

After executing the code above, Cognito returns in Unity the following answer indicating that the user is not confirmed yet and that an email has been sent:

Let’s check it; a new user appeared in the User Pool with an unconfirmed status:

And we received a no-reply email with the confirmation code:

The Signup Confirmation: The User Way

This is the signup confirmation function in Unity:

Notes:

  • We send the three mandatory attributes specified in the Cognito documentation: the username, the confirmation code we received by email, and the User Pool application ID.
  • We specify the value AWSCognitoIdentityProviderService.ConfirmSignUp as a header.

After executing the code above, we can observe that the signup has been confirmed:

The user can now log in.

The Signup Confirmation: The Admin Way

Once the user has been created, we can confirm it with a Lambda function in this way:

Notes:

The Signup Confirmation: The Automatic Way

Another way to confirm the user’s signup is by using a Cognito trigger and a Lambda function.

First of all, we create our Lambda function:

We indicate to Cognito that the user is confirmed, as specified in the Cognito documentation.

Then, we create a pre-sign-up Lambda trigger in Cognito, and we attach our Lambda function:

Go back to Unity. We execute the signup function, and Cognito returns a message indicating that the signup has been automatically confirmed. No email has been sent, and we don’t need the Unity confirmation function.

Costs

Unless you have more than 50,000 MAUs (monthly active users) in your User Pool, Cognito is totally free! Unity3D is also free unless you want to unlock some specific options.

Note that there is a limitation for email sending with Cognito. If you need to send more than 50 emails daily, you should use SES. Suppose that your game is a huge success and has 30k new users in a month; your signup system would cost 3.00 USD monthly.

Closing Thoughts

This article shows three ways of building a whole signup flow using Unity3D and AWS Cognito: with user email confirmation, with admin confirmation, and with automatic confirmation.

I truly hope you liked this article. If you have any questions, don’t hesitate to get in touch with me on my social media. I will be glad to answer you!

Thanks for reading!

The post Building a Simple Signup Flow With Unity3D and AWS Cognito appeared first on ab.

]]>