Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Unable to validate token error 401 when using SignInWithOculusAsync()

Discussion in 'Authentication' started by MyMinia, Dec 20, 2022.

  1. MyMinia

    MyMinia

    Joined:
    Apr 15, 2021
    Posts:
    5
    Hello, I am trying to use the new Oculus sign in capabilities of the Authentication package by using the example script provided for Oculus SignIn, however I get the next error when I try to use : AuthenticationService.Instance.SignInWithOculusAsync(oculusNonce, userId);

    Project Information :
    Unity 2021.3.15f1
    Authentication 2.3.1

    [Authentication]: Request failed: 401, {"title":"PERMISSION_DENIED","detail":"unable to validate token","details":[],"status":401}
    UnityEngine.Logger:LogError (string,object)
    Unity.Services.Authentication.Logger:LogError (object) (at Library/PackageCache/com.unity.services.authentication@2.3.1/Runtime/Utilities/Logger.cs:18)
    Unity.Services.Authentication.AuthenticationServiceInternal:BuildServerException (Unity.Services.Authentication.WebRequestException) (at Library/PackageCache/com.unity.services.authentication@2.3.1/Runtime/AuthenticationServiceInternal.cs:796)
    Unity.Services.Authentication.AuthenticationServiceInternal/<HandleSignInRequestAsync>d__108:MoveNext () (at Library/PackageCache/com.unity.services.authentication@2.3.1/Runtime/AuthenticationServiceInternal.cs:526)
    System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<Unity.Services.Authentication.SignInResponse>:SetException (System.Exception)
    Unity.Services.Authentication.WebRequest/<SendAsync>d__15`1<Unity.Services.Authentication.SignInResponse>:MoveNext () (at Library/PackageCache/com.unity.services.authentication@2.3.1/Runtime/Network/WebRequest.cs:63)
    System.Threading.Tasks.TaskCompletionSource`1<string>:SetException (System.Exception)
    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@2.3.1/Runtime/Network/WebRequest.cs:193)
    Unity.Services.Authentication.WebRequest/<>c__DisplayClass16_0:<SendAttemptAsync>b__0 (UnityEngine.AsyncOperation) (at Library/PackageCache/com.unity.services.authentication@2.3.1/Runtime/Network/WebRequest.cs:76)
    UnityEngine.AsyncOperation:InvokeCompletionEvent ()

    Why does this error happens and how to solve it ?
     
  2. TijsVdV

    TijsVdV

    Joined:
    Mar 7, 2017
    Posts:
    32
    Experiencing the same issue!
     
  3. mahdik_unity

    mahdik_unity

    Unity Technologies

    Joined:
    Sep 16, 2021
    Posts:
    15
    Hello, thank you for your message,

    please verify these information:
    - Ensure your app id and app secret are correct
    - Ensure your app passed the data use checkup required by Oculus to be able to use their Authentication service
    - Ensure your test user passed the entitlement check! more info: Entitlement Check for Meta Store Apps: Unity | Oculus Developers
     
  4. MyMinia

    MyMinia

    Joined:
    Apr 15, 2021
    Posts:
    5
    I resolved the issue by granting authorization of the AppID in the Oculus Dashboard Data Use Check Up
     
    chengg_unity likes this.
  5. TijsVdV

    TijsVdV

    Joined:
    Mar 7, 2017
    Posts:
    32
    I still having trouble getting this to work. I still ge tRequest failed: 401, {"title":"PERMISSION_DENIED","detail":"unable to validate token","details":[],"status":401}

    I verified:
    - app id and secret are correct
    - Data use checkup is done
    - I pass the entitlments check with my developer account

    And still when i use the SignInWithOculusAsync it refuses me. Getting desperate here :(

    Edit: Just noticed when i set my details in the editor i get the same error
     
  6. TijsVdV

    TijsVdV

    Joined:
    Mar 7, 2017
    Posts:
    32
    I checked the Data use Check but don't see a part that says to approve the app id?
     
  7. MyMinia

    MyMinia

    Joined:
    Apr 15, 2021
    Posts:
    5
  8. TijsVdV

    TijsVdV

    Joined:
    Mar 7, 2017
    Posts:
    32
    I have that one approved. So that does not seem to be the problem.
     
  9. mahdik_unity

    mahdik_unity

    Unity Technologies

    Joined:
    Sep 16, 2021
    Posts:
    15
    hello @TijsVdV,

    please send me a direct message with your project id so that I can assist you further. Thank you
     
  10. TijsVdV

    TijsVdV

    Joined:
    Mar 7, 2017
    Posts:
    32
    I found the issue btw, there was an error with the OculusId we where passing to to login function. All solved now!
     
    mahdik_unity likes this.
  11. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    88
    I just upgraded to Unity 2021.3.21 (macOS) and am now getting this error on device, but the exact same code worked when using 2021.3.18. Also worth noting that when I rollback, I have to revert any automatic changes (packages.json etc) that upgrading to 2021.3.21 did, otherwise the error persists.
     
  12. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    88
    This issue persists for me for versions 2021.3.22 and 2021.3.23.
     
  13. NuclearCookieTF

    NuclearCookieTF

    Joined:
    Mar 29, 2021
    Posts:
    17
    Hey @justdizzy

    We had the same problem and managed to find out why.
    Unity 2021.3.21 fixes a problem where, if you upgraded before from Unity 2020.3, your code stripping level was changed to a lower value than expected. When upgrading our project from 2021.3.9f1 to 2021.3.21f1, this actually caused our code stripping to go up (!) from minimal to low.

    This is the entry in the changelog:

    IL2CPP: Projects created prior to 2021.3 and opened in 2021.3 or newer could have their Managed Stripping Level incorrectly migrated to the new default value of Minimal when the old default of Low should have been retained. (UUM-19512)​

    The issue with Oculus authentication is caused by code stripping. You can fix it by changing back to Minimal code stripping, or by adding a link.xml file in your project with this content:

    Code (CSharp):
    1. <linker>
    2. <assembly fullname="Unity.Services.Authentication" preserve="all" />
    3. </linker>
    I confirmed this works.
    Unity's Authentication team helped me track this down and they will fix the package with code stripping soon.
     
    Claytonious, justdizzy and SebT_Unity like this.
  14. LittleDreamerGames

    LittleDreamerGames

    Joined:
    Apr 9, 2017
    Posts:
    72
    I upgraded Unity to 2021.3.28f1, grabbed the latest Authentication service, and now it works.

    I'm trying this out for the first time so I can save to the cloud but I'm getting the same error. Here's what I've done:

    Meta Quest Dashboard
    • Under API I retrieved the following
      • User ID
      • App ID
      • App Secret
    • Data Use Checkup
      • Both User ID and User Profile have been approved
    Unity Editor
    • Project Settings > Services > Authentication
      • Added Oculus Identifier
      • Set App ID to the one in the above steps
      • Set App Secret from the one in the above steps
    • Project Settings > Services
      • Unity Project ID is set and points to my project and organization
    • Project Settings > Player > Managed Stripping Level
      • Set to Low
    • OculusPlatformSettings
      • Application ID > Meta Quest/2/Pro set to the App ID from the above steps.
    At runtime on the Meta Quest 2
    • Initialize the platform
    • Entitlement passes
    • I am able to retrieve the User.ID and Nonse.
      • The User.ID matches the one under API on the Meta Quest Dashboard for the game
      • UserProof.Value (Nonse) is a Super long string that changes every time it is retrieved
    • AuthenticationService.Instance.SignInWithOculusAsync
      • Pass in UsesrProof.Value and User.ID
      • I get the same exception as the OP
    Versions
    • Unity
      • 2020.3.48f1
    • Authenticate
      • 2.4.0
    • Cloud Save
      • 2.0.1
    I've been successfully using Meta Quest Dashboard > Leaderboards.
     
    Last edited: Jul 18, 2023