Unity and Developer authenticated identities

0

Hello. I'm trying to use Cognito Developer authenticated identities inside a Unity project. But I can't get it to work and when searching inside the documentation, I can't find a clear/simple example of what I should do. I apologize in advance if some questions/remarks seem simple or stupid, but I'm not a "true web developer" and some notions can be a little bit confusing to me...

What I'm trying to accomplish is login on an existing backend (this code already exists and works fine), and then access AWS functionalities, such as S3 storage, to be able to save files for the logged user. From what I understand, this is what Cognito identity pools are intented for. The first thing I'm not sure about is do I have to create also a user pool to use that functionality or not ? (I'd say no, but I'm not sure).

So I started reading the documentation and followed what I found on this page. I created a CognitoAWSCredentials class looking like that :

public class DeveloperAuthenticatedCredentials : CognitoAWSCredentials
{
    const string IDENTITY_POOL = "us-east-1:2d36xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    static readonly Amazon.RegionEndpoint REGION = Amazon.RegionEndpoint.USEast1;
    private string m_LoginEmail = null;
    private int m_LoginId = -1;

    public DeveloperAuthenticatedCredentials (string _loginEmail, int _loginId) : base(IDENTITY_POOL, REGION)
    {
        m_LoginEmail = _loginEmail;
        m_LoginId = _loginId;
    }
    ...

I also read that I have to override the RefreshIdentity() method and that's where I'm having questions :

    protected override IdentityState RefreshIdentity()
    {
        IdentityState state = null;
        string identityId = IDENTITY_POOL; // should it be the user id on my server ?
        string token = AccessToken; // OpenID token ?
        state = new IdentityState(identityId, "myCustomProviderName", token, false);

        return state;
    }

1- Since I already performed the sign-in operation successfully on the existing server, do I need to use a coroutine or can I just create the IdentityState with the information I have ? Or should I re-write the entire login process and include the Cognito Authentification during this phase ? If yes, are there some specific values I should add in the response ?

2- What exactly is the "identityId" string I should pass to the IdentityState variable ? Is it the user id on my server or is it the IDENTITY_POOL I specified in the credentials constructor ? During my test, I sometimes got a message that the identityId was not in correct form when I tried passing my user id.

3- Do I have to use the Async method ? I found somewhere in the documentation (can't find where, I'll try editing this post once I do) that in C# the GetIdentityAsync() method should be used. Is it also the case in Unity ?

4- What about the GetOpenIdTokenForDeveloperIdentityRequest (and its Async version) : from what I understand, I have to call one of them at some point and specify in the logins a pair "myCustomProviderName", "myUserId".

I will probably have some more questions in the future, but replies to these ones will provide a big help for me.

Thanks in advance.

asked 2 years ago100 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions