This document is about: SERVER 5
SWITCH TO

Photon Oculus Authentication

伺服器配置

  • 開啟 "deploy\NameServer\bin\NameServer.xml.config"。
  • 確保CustomAuth被啟用,Enabled需要為true。
  • 根據您的需要,可以選擇將AllowAnonymous設置為true或false。 我們建議將其設置為false。
  • 將AuthenticationType設置為 "3",這是Oculus認証提供者類型的代碼。
  • 選擇您想要的任何名字,我們在這個例子中使用 "Oculus",但您可以更改。
  • 必需將 "AuthUrl "留空,但我們不需要使用它,因為認証端點是內部的。
  • 下面是其他Oculus特定任務設置的列表及其說明:

XML

  <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>

客戶端代碼

Oculus根據用戶的Oculus ID和客戶端提供的nonce對用戶進行驗証。 在代碼中,nonce是一個任意的數字,只能使用一次。 閱讀更多點此

獲取憑證

客戶端需要登錄到Oculus,然后生成一個nonce。 這個nonce是証明客戶端是一個有效的Oculus用戶。 您可以從他們的網站獲得Oculus SDKs。

Unity說明

下載Oculus Platform SDK for Unity並將其導入到您的項目中。 從編輯器的選單欄,進入 "Oculus Platform"->"編輯設置",輸入您的Oculus AppId。 使用下面的代碼來獲取登錄用戶的Oculus ID並生成一個nonce:

C#

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
        }
    }
}

憑證

客戶端需要發送Oculus ID和生成的nonce作為查詢字符串參數,並分別使用關鍵字 "userid "和 "nonce ":

Back to top