server | v5 switch to v4  

Photon Oculus Authentication

Contents

Server Configuration

  • Open "deploy\NameServer\bin\NameServer.xml.config".
  • Make sure CustomAuth is enabled, Enabled needs to be true.
  • Optionally set AllowAnonymous to true or false depending on your needs. We recommend setting it to false.
  • Set AuthenticationType to "3" which is the code for Oculus authentication provider type.
  • Choose any name you want, we used "Oculus" for this example but you can change it.
  • Leave "AuthUrl" empty as it's required but we don't need it as the authentication endpoint is internal.
  • Find below the list of the other Oculus specific mandatroy settings with their description:
  <CustomAuth Enabled="true" AllowAnonymous="false">
    <AuthProviders>
      <AuthProvider Name="Oculus"
                    AuthenticationType="3"
                    AuthUrl=""
                    appid="Replace with ID of your Oculus App"
                    appsecret="Replace with secret for your Oculus App." />
    </AuthProviders>
  </CustomAuth>

Back To Top

Client Code

Oculus verifies users based on their Oculus ID and a client-provided nonce. In cryptography, a nonce is an arbitrary number that can only be used once. Read more here.

Back To Top

Get Credentials

Client needs to log in to Oculus then generate a nonce. This nonce is proof that the client is a valid Oculus user. You can get Oculus SDKs from their website.

Back To Top

Unity Instructions

Download Oculus Platform SDK for Unity and import it to your project. From the Editor's menu bar, go to "Oculus Platform" -> "Edit Settings" and enter your Oculus AppId. Use the following code to get the logged in user's Oculus ID and generate a nonce:

using UnityEngine;
using Oculus.Platform;
using Oculus.Platform.Models;

public class OculusAuth : MonoBehaviour
{
    private string oculusId;

    private void Start()
    {
        Core.AsyncInitialize().OnComplete(OnInitializationCallback);
    }

    private void OnInitializationCallback(Message<PlatformInitialize> msg)
    {
        if (msg.IsError)
        {
            Debug.LogErrorFormat("Oculus: Error during initialization. Error Message: {0}",
                msg.GetError().Message);
        }
        else
        {
            Entitlements.IsUserEntitledToApplication().OnComplete(OnIsEntitledCallback);
        }
    }

    private void OnIsEntitledCallback(Message msg)
    {
        if (msg.IsError)
        {
            Debug.LogErrorFormat("Oculus: Error verifying the user is entitled to the application. Error Message: {0}",
                msg.GetError().Message);
        }
        else
        {
            GetLoggedInUser();
        }
    }

    private void GetLoggedInUser()
    {
        Users.GetLoggedInUser().OnComplete(OnLoggedInUserCallback);
    }

    private void OnLoggedInUserCallback(Message<User> msg)
    {
        if (msg.IsError)
        {
            Debug.LogErrorFormat("Oculus: Error getting logged in user. Error Message: {0}",
                msg.GetError().Message);
        }
        else
        {
            oculusId = msg.Data.ID.ToString(); // do not use msg.Data.OculusID;
            GetUserProof();
        }
    }

    private void GetUserProof()
    {
        Users.GetUserProof().OnComplete(OnUserProofCallback);
    }

    private void OnUserProofCallback(Message<UserProof> msg)
    {
        if (msg.IsError)
        {
            Debug.LogErrorFormat("Oculus: Error getting user proof. Error Message: {0}",
                msg.GetError().Message);
        }
        else
        {
            string oculusNonce = msg.Data.Value;
            // Photon Authentication can be done here
        }
    }
}

Back To Top

Authenticate

Client needs to send the Oculus ID and generated nonce as query string parameters with the respective keys "userid" and "nonce":


To Document Top