Aws-sdk-net: FeatureRequest: Unity and CognitoIdentityProvider

Created on 14 Apr 2017  路  10Comments  路  Source: aws/aws-sdk-net

Hi,

I'm building a Unity project where an authentication system is required.
I'm using AWS CognitoIdentityProvider to allow user's to authenticate with a login/password.

My problem was that CognitoIdentityProvider is not part of the AWS Unity SDK.
After digging i discovered this repository where there is an SDK for every AWS services. So i played with AWS SDK .NET and here are the steps to generate your own CognitoIdentityProvider.dll for Unity:

  1. Clone the repository https://github.com/aws/aws-sdk-net
  2. Edit the file "aws-sdk-net\generator\ServiceModels\cognito-idp\metadata.json" and add at the root of the json
"platforms": ["Unity"], 
  1. Then open the solution "aws-sdk-net\generator\AWSSDKGenerator.sln" and launch the project. It should generate all the sources for the Unity version of CognitoIdentityProvider
  2. Then open the solution "aws-sdk-net\generator\AWSSDK.Unity.sln" and build the project
  3. Go in the folder "aws-sdk-net\sdk\src\Services\CognitoIdentityProvider\bin\Release\unity\".
    Copy the file "AWSSDK.CognitoIdentityProvider.dll" and "AWSSDK.CognitoIdentityProvider.pdb" in your Unity project
  4. Taaadddaaaaa.

I tested it and its working well.
Here are the methods i tested and i'm using in my project on Windows and Android (On the object AmazonCognitoIdentityProviderClient) :

  • InitiateAuthAsync
  • RespondToAuthChallengeAsync
  • GlobalSignOutAsync
  • SignUpAsync
  • ConfirmSignUpAsync
  • ResendConfirmationCodeAsync
  • ForgotPasswordAsync
  • ConfirmForgotPasswordAsync
  • ChangePasswordAsync

There is probably some good reasons why all of the services are not available for Unity but i can't find one for CognitoIdentityProvider.

So my request is : Since apparently there is no issues with CognitoIdentityProvider and Unity and very little work to do (literally one line of code + testing), could you add it to the official AWS Unity SDK ? Or am i missing something ?

One important note: Use Visual Studio 2017, with the 2015 version its a far more complex process.

Unity closed-for-staleness feature-request

Most helpful comment

I can't believe that this isn't included in the SDK already. I mean even amazon itself posted this article describing an application model were the client fetches access tokens and passes them to the server for games https://aws.amazon.com/blogs/gametech/how-to-set-up-player-authentication-with-amazon-cognito/.

I am really not trying to be negative here, however I did invest a significant amount of time trying to figure out how to do this in Unity, before I figured out it wasn't even in the SDK. I mean, wouldn't authentication be one of the highest priorities for an SDK for a game engine?

Please add this.

All 10 comments

Apologies for cluttering the comments

@Greu Our team has been searching for a solution to this issue. We are also actively looking for a developer who may be able to assist in related areas. Great budget and remote work! If you are interested, you can email me at [email protected]. Would love to discuss the details.

@Greu Update: We are having issues with steps 3, 4, & 5 - hoping you can assist. You mentioned in your comment

"Open the solution "aws-sdk-net\generator\AWSSDKGenerator.sln" and launch the project. It should generate all the sources for the Unity version of CognitoIdentityProvider"

I have been using MonoDevelop but downloaded Visual Studio to open the .sln file. Inside visual studio I am able to build the AWSSDKGenerator.sln solution. How do I know that the build properly generated all the sources for the Unity version of CognitoIdentityProvider?

For the next step, "AWSSDK.Unity.sln" is now located inside adw-sdk-net/sdk/ not aws-sdk-net/generator/AWSSDK.Unity.sln. When I attempt to build that solution, I receive a few error messages regarding the using headers at the top of the file.

using Amazon.Util;
using Amazon.Util.Internal;

Any ideas?

Update
We've located an error when performing a build in Visual Studio. The error comes from line 109 of program.cs inside the ServiceClientGenerator folder. Program.cs makes a call to the RemoveOrphanedShapes function inside ServiceClientGeneratorLib/GeneratorDriver.cs file. Here is the error

Could not find a part of the path Users/dailenspencer/projects/Unity/aws-sdk-net/sdk/src\Services

I'm running OSX - not sure if the backslash \ would cause the issue. I attempted to change it toa forward slash /. But that caused some other issues.

@dailenspencer I cloned the repository and tried to follow the checklist i did a few month ago. A few things changed but its still working well.

Try that:

  • First things you need Visual Studio 2017! Not monodevelop and not Visual Studio 2015. The community edition with Unity works fine.
  • Clone the repository https://github.com/aws/aws-sdk-net
  • Edit the file "aws-sdk-net\generator\ServiceModels\cognito-idp\metadata.json" and add at the root of the json
    "platforms": ["Unity"],
  • Then open the solution "aws-sdk-net\generator\AWSSDKGenerator.sln" and launch the project (Click on the green "play" triangle). A cmd window should open and it should generate all the sources for the Unity version of CognitoIdentityProvider. A file "AWSSDK.CognitoIdentityProvider.Unity.csproj" should appear in the folder "aws-sdk-net\sdk\src\Services\CognitoIdentityProvider" if everything goes well.
  • Then open the solution "aws-sdk-net\sdk\AWSSDK.Unity.sln". Change the build type to "Release" and build the solution (CTRL+Shift+B or go in the build menu -> Build Solution). A new folder "bin" should appear in "aws-sdk-net\sdk\src\Services\CognitoIdentityProvider" if it works.
  • Go in the folder "aws-sdk-net\sdk\src\Services\CognitoIdentityProvider\bin\Release\unity".
  • Copy the file "AWSSDK.CognitoIdentityProvider.dll" and "AWSSDK.CognitoIdentityProvider.pdb" in your Unity project
  • Taaadddaaaaa.

@dailenspencer @Greu

I'm having trouble with this on the Mac too. I found that I could get the AWSSDKGenerator to work by changing the slashes in SolutionFileCreator.cs

            //var projectPath = @"..\..\..\..\sdk\" + extraTestProject;
            var projectPath = @"../../../../sdk/" + extraTestProject;

I now have the AWSSDK.Unity.sln, but am having trouble building it because of the same errors about Amazon.Util and Amazon.Util.Internal. It can't find the Util namespace within the Amazon namespace.

Any ideas? The files are there on disk, so I think I just have a setup issue in Visual Studio, but I can't find it.

I just want to go "Taaadddaaaaa" too!

@emalb

I did a search for all of the instances of UnityPath inside aws-sdk-net. Checkout line 265 in ServiceClientGeneratorLib/Generators/ProjectFiles/UnityProjectFile.cs.

Path.Combine((string)this.Session["UnityPath"], "Editor", "Data", "PlaybackEngines", "windowsstandalonesupport", "Managed", "UnityEngine.dll")

The issue here is that the path above..
{UnityPath}/Editor/Data/Playback/and so on....
Does not match up with a viable path on your mac. And theres about a dozen instances of code like this throughout the code(maybe more). So option 1 is to move through each instance and change to correct paths. Option 2 is wait until they release for osx platforms. :/

I found this repo which helped me out though
https://github.com/guywald/serverless-auth-msg-board-unity3d-client

I managed to generate the CognitoIdentityProvider. For those who are still confused, I'll try clarify some extra steps.

  1. Get Windows. Tried on Mac. Didn't work.
  2. Download Visual Studio 2017. You will need to install desktop C# and Unity development components.
  3. Follow steps detailed @Greu in this comment above.
  4. Move the built files into Unity, alongside with the other imported AWS libraries if you like. The generated code will also work with Unity on Mac.

@Greu I humbly thank you for figuring this out and sharing it! You saved me many hours of grief.

Thank you!

I followed steps detailed by @Greu but still can't get it working.

  • Environment

    • Windows 10

    • Visual Studio Community 2017 v15.5.3 with Visual Studio Tools for Unity and Desktop C# Package

    • Unity 2017.3.0f3

ServiceClientGenerator.exe's output shows that argument exceptions are thrown while executing, but AWSSDK.CognitoIdentityProvider.Unity.csproj is generated successfully.
Then I opened aws-sdk-net\sdk\AWSSDK.Unity.sln and found that UnityEngine namespace is grayed out and UnityEngine.dll is not referenced correctly. I don't know what I am missing... Tried re-installation of VS but no effect.


Update:
I edited line 265 in ServiceClientGeneratorLib/Generators/ProjectFiles/UnityProjectFile.cs (mentioned once above) and changed the UnityEngine.dll's path from Path.Combine((string)this.Session["UnityPath"], "Editor", "Data", "PlaybackEngines", "windowsstandalonesupport", "Managed", "UnityEngine.dll")) to Path.Combine((string)this.Session["UnityPath"], "Editor", "Data", "Managed", "UnityEngine.dll")). This solved the problem for me, I haven't tried if the dll built works well though.

I can't believe that this isn't included in the SDK already. I mean even amazon itself posted this article describing an application model were the client fetches access tokens and passes them to the server for games https://aws.amazon.com/blogs/gametech/how-to-set-up-player-authentication-with-amazon-cognito/.

I am really not trying to be negative here, however I did invest a significant amount of time trying to figure out how to do this in Unity, before I figured out it wasn't even in the SDK. I mean, wouldn't authentication be one of the highest priorities for an SDK for a game engine?

Please add this.

We have noticed this issue has not recieved attention in a year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

Was this page helpful?
0 / 5 - 0 ratings