Authentication now supports Code Link!

Hello everyone,

We are excited to announce that Code Link is now live with Authentication 3.0.0! This feature allows players to easily switch devices or platforms by using a generated code, all without the need to input their login credentials.

Before Code Link, the support for cross-platform or cross-progression was limited. For example, there wasn’t an easy way for a player on Steam to continue their progress on consoles. Now, with Code Link, an authenticated player can seamlessly sign in to any other platform or device.

Demo
You can see it in action here:
9250419--1293309--upload_2023-8-25_11-54-29.gif

Documentation
You can refer to our documentation (API and SDK) on how to set up and configure Code Link.

Very cool! Was just looking for something like this and found the announcement.

I have updated the Authentication package but I’m having issues. The updated codebase doesn’t recognise
GenerateCodeAsync (and possibly some of the other new functions).

Did I do the update wrong? Or is this a bug?

Can you share more information, for example the version of your authentication package, the code that throws the error and the full error message?

No error message, VS code just doesnt show the package has any of the new functions.

The version of Authentication is 3.0.0, and Roslyn doesn’t identify the method:


Does it also show the errors inside Unity? I don‘t see the second and third screenshot, they are unavailable. Have you tried it with a different IDE like VS or Rider?

I just verified and noticed a small error, it should be GenerateSignInCodeAsync.
The documentation is showing GenerateCodeAsync, we will update it.

Thanks this solved it. Couldn’t see the standard procedures up until now. Just a note: the SDK page’s code examples as well as the diagrams still show GenerateCodeAsync. I think blindly copying the examples is what led me to my error the first time.

Authentication version 3.3.3.
Android Build.

  1. An error occurs when building with Android and testing with two LDPLAYERs. (one sign in anonymously)

WebRequestException: {“detail”:“invalid sign in code”,“details”:,“status”:400,“title”:“INVALID_PARAMETERS”}

  1. I enter the same code in the Unity editor play mode, it will succeed!
    I don’t know what’s wrong. Does it not work on the same type of device?

  2. I issued the code in the Unity editor and entered the code on a real Android device, but it failed.

It feels like the “AuthenticationService.Instance.GetSignInCodeInfoAsync” function is working incorrectly on Android devices.

1 Like

Authentication version 3.3.3.
Codelink doesn’t seem to work in the Android environment.

It works because it is implemented using rest API. (used BestHTTP)
“GetSignInCodeInfoAsync” functions and the “ConfirmCodeAsync” function

Authentication version 3.4.0 · November 28, 2024

Hello, I’m trying to use Code Link. It works fine in testing, I’m trying to figure out the polling method Code-Link

Doc just says:

Note: The SignInWithCodeAsync method also allows for automatic polling (every five seconds), so the device automatically signs the player in after the code has been authorized, or throws an exception if the code has expired. This method also accepts a CancellationToken to cancel the polling.

when I enable this option to true, I’m hit with this error on the first poll.
How is this method supposed to be used exactly? isn’t the point of polling so my Device B doesn’t have to click Confirm after their code was confirmed valid on Device A ?
Am I misunderstanding what polling supposed to do ?

[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_0:<SendAttemptAsync>b__0 (UnityEngine.AsyncOperation) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Network/WebRequest.cs:76)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()

And

Unity.Services.Core.RequestFailedException: Unknown error completing sign-in. ---> Unity.Services.Core.RequestFailedException: Failed to decode and verify access token.
  at Unity.Services.Authentication.AuthenticationServiceInternal.CompleteSignIn (System.String accessToken, System.String sessionToken, System.Boolean enableRefresh, Unity.Services.Authentication.User user, System.String lastNotificationDate) [0x00010] in .\Library\PackageCache\com.unity.services.authentication\Runtime\AuthenticationServiceInternal.cs:342 
   --- End of inner exception stack trace ---
  at Unity.Services.Authentication.AuthenticationServiceInternal.CompleteSignIn (System.String accessToken, System.String sessionToken, System.Boolean enableRefresh, Unity.Services.Authentication.User user, System.String lastNotificationDate) [0x00112] in .\Library\PackageCache\com.unity.services.authentication\Runtime\AuthenticationServiceInternal.cs:380 
  at Unity.Services.Authentication.AuthenticationServiceInternal.CompleteSignIn (Unity.Services.Authentication.SignInResponse response, System.Boolean enableRefresh) [0x00000] in .\Library\PackageCache\com.unity.services.authentication\Runtime\AuthenticationServiceInternal.cs:332 
  at Unity.Services.Authentication.AuthenticationServiceInternal.HandleSignInRequestAsync (System.Func`1[TResult] signInRequest, System.Boolean enableRefresh) [0x00096] in .\Library\PackageCache\com.unity.services.authentication\Runtime\AuthenticationServiceInternal.cs:283 
  at Unity.Services.Authentication.AuthenticationServiceInternal.SignInWithCodeAsync (System.Boolean usePolling, System.Threading.CancellationToken cancellationToken) [0x001ad] in .\Library\PackageCache\com.unity.services.authentication\Runtime\AuthenticationServiceInternal.CodeLink.cs:73 
  at Authentication.PollSignInWithCodeAsync () [0x00045] in P:\UNITY\Temp\AuthCodeSignIn\Assets\Authentication.cs:131 
UnityEngine.Debug:Log (object)
Authentication/<PollSignInWithCodeAsync>d__21:MoveNext () (at Assets/Authentication.cs:135)
System.Runtime.CompilerServices.AsyncTaskMethodBuilder:SetException (System.Exception)
Unity.Services.Authentication.AuthenticationServiceInternal/<SignInWithCodeAsync>d__16:MoveNext () (at ./Library/PackageCache/com.unity.services.authentication/Runtime/AuthenticationServiceInternal.CodeLink.cs:79)
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_0:<SendAttemptAsync>b__0 (UnityEngine.AsyncOperation) (at ./Library/PackageCache/com.unity.services.authentication/Runtime/Network/WebRequest.cs:76)
UnityEngine.AsyncOperation:InvokeCompletionEvent ()
1 Like

I’m getting the same exception. I haven’t seen your post here before and ended up creating this new thread: Code-Link SignInWithCodeAsync error

hey @erickb_unity, do have any idea of the reason for this issue?

@edit:
I’ve found the reason for the issue and added details to my thread: Code-Link SignInWithCodeAsync error
@erickb_unity, could you please take it to Unity Engineers?

1 Like

awesome find, thank you :saluting_face:

1 Like

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