Code-Link SignInWithCodeAsync error

Hi, I’m implementing the Code-Link into my game, and while I was able to make it work, there is the Pooling feature I would like to use, but I get the same error all the time. Maybe I did not understand how it works, and I am coming here to ask for help.

My implementation is simply like this:

// Based on: https://docs.unity.com/ugs/en-us/manual/authentication/manual/platform-signin-code-link
private async Task Execute(CancellationToken cancellationToken)
{
    string identifier = SystemInfo.deviceName;

    try
    {
        var codeInfo = await AuthenticationService.Instance.GenerateSignInCodeAsync();
        await AuthenticationService.Instance.SignInWithCodeAsync(true, cancellationToken);
        Debug.Log("Sign-In with Code succeeded")
    }
    catch (Exception e)
    {
        Debug.LogException(e);
    }
}

Exception:
[Authentication]: That is not a valid token (expected 3 parts but has 1).

Check the stacktrace:
[Authentication]: That is not a valid token (expected 3 parts but has 1).

UnityEngine.Logger:LogError (string,object)
Unity.Services.Authentication.Logger:LogError (object) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Utilities/Logger.cs:18)
Unity.Services.Authentication.JwtDecoder:Decode<Unity.Services.Authentication.AccessToken> (string) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Utilities/Jwt/JwtDecoder.cs:29)
Unity.Services.Authentication.AuthenticationServiceInternal:CompleteSignIn (string,string,bool,Unity.Services.Authentication.User,string) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/AuthenticationServiceInternal.cs:339)
Unity.Services.Authentication.AuthenticationServiceInternal:CompleteSignIn (Unity.Services.Authentication.SignInResponse,bool) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/AuthenticationServiceInternal.cs:332)
Unity.Services.Authentication.AuthenticationServiceInternal/<HandleSignInRequestAsync>d__127:MoveNext () (at ./Library/PackageCache/com.unity.services.authentication/Runtime/AuthenticationServiceInternal.cs:278)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:Start<Unity.Services.Authentication.AuthenticationServiceInternal/<HandleSignInRequestAsync>d__127> (Unity.Services.Authentication.AuthenticationServiceInternal/<HandleSignInRequestAsync>d__127&)
Unity.Services.Authentication.AuthenticationServiceInternal:HandleSignInRequestAsync (System.Func`1<System.Threading.Tasks.Task`1<Unity.Services.Authentication.SignInResponse>>,bool)
Unity.Services.Authentication.AuthenticationServiceInternal/<SignInWithCodeAsync>d__16:MoveNext () (at ./Library/PackageCache/com.unity.services.authentication/Runtime/AuthenticationServiceInternal.CodeLink.cs:73)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Authentication.SignInResponse>:SetResult (Unity.Services.Authentication.SignInResponse)
Unity.Services.Authentication.AuthenticationServiceInternal/<PollForCodeConfirmationAsync>d__17:MoveNext () (at ./Library/PackageCache/com.unity.services.authentication/Runtime/AuthenticationServiceInternal.CodeLink.cs:110)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Authentication.SignInResponse>:SetResult (Unity.Services.Authentication.SignInResponse)
Unity.Services.Authentication.WebRequest/<SendAsync>d__15`1<Unity.Services.Authentication.SignInResponse>:MoveNext () (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Network/WebRequest.cs:66)
System.Threading.Tasks.TaskCompletionSource`1<string>:SetResult (string)
Unity.Services.Authentication.WebRequest:RequestCompleted (System.Threading.Tasks.TaskCompletionSource`1<string>,long,bool,bool,string,string,System.Collections.Generic.IDictionary`2<string, string>) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Network/WebRequest.cs:198)
Unity.Services.Authentication.WebRequest/<>c__DisplayClass16_1:<SendAttemptAsync>b__0 (UnityEngine.AsyncOperation) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Network/WebRequest.cs:76)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()

Okay, I’ve moved the com.unity.services.authentication version 3.3.3 to my local Packages folder to realize some debugging and found the issue.

The idToken is getting checked against null only, but it can also be string.Empty, so I’ve just modified both if checks, and both Pooling and Non-pooling methods are working as expected.

Now we need a Unity engineer to apply the fix and release a new version for us.

Hey! Thanks for the information, I have forwarded this to the team responsible for the package.

Hi, is there any news on this matter ? I am still experiencing the issue, I run this script after generating the code awaiting confirmed code, with a button works fine, but polling still producing this error.. How do we poll then? , am I doing something wrong or is this issue not resolved ?
Really need this feature for seamless login :frowning:

//after code generated
await Task.Run(() => PollSignInWithCodeAsync());
    CancellationTokenSource CodeLinkCancellationTokenSource;
    public async Awaitable PollSignInWithCodeAsync()
    {
        await Awaitable.MainThreadAsync();
        try
        {
            CodeLinkCancellationTokenSource = new CancellationTokenSource();
            await AuthenticationService.Instance.SignInWithCodeAsync(true, CodeLinkCancellationTokenSource.Token);
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }

I’m using Authentication package 3.4.1

hey @navarone771, answering your DM here so others can also help or be helped…

I haven’t updated my package version after my changes, so I do not even know if my fix was implemetend on the newer versions. Have you tried running the version 3.3.3 with my fix?

Also, using your current version, you can move the package from the Library\PackageCache to Packages and debug with breakpoints to figure out the reason for the exception.

Hi @sandolkakos , appreciate the help. It doesn’t seem fix was implemented… If you don’t mind clarify the steps on how exactly would I go about running version 3.3.3 with your fix, do I need to move a package or something ?

hi @navarone771, to apply my fix you have to move the com.unity.services.authentication package from your cache to the Packages folder so it becomes an Embedded Package, which can be editted and pushed to your repository. You are gonna be using this embedded package till they release a fix.

Step 1: Go to your project folder and then: Library/PackageCache

Step 2: Move the folder com.unity.services.authentication@x.x.x to: YourProject/Packages folder. (it should be side by side the manifest.json)

Step 3: Close your IDE and in Unity open any script, so it refreshes the references of the package, which is now edittable.

Step 4: Apply my fix and test if you still have the issue.

hey @GabKBelmonte, do you have any feedback from the team responsible for the package? I just noticed the newest package 3.5.2 still has the issue with if (response.IdToken != null) not being correct since idToken is a string that can be string.empty.

Bump, you would think a company with as much money as Unity would have the time to change 2 lines.

Hello!

The fix is indeed in, it will be part of the next release of the package.
Cheers!

The fix is available with version 3.6.0: Changelog | Authentication | 3.6.0