PUN Classic (also called PUN1) is the original and first major version of PUN. It is now replaced by PUN2 which is refactored and enhanced. We highly recommend starting new projects with PUN2 and if possible migrating existing ones from PUN1 to PUN2 by following our "Migration Notes". PUN Classic will be maintained for the coming months. We will fix important bugs and support new Unity versions but new features will be added only to PUN2.

Photon Oculus Authentication

Contents

應用程序設置

添加Oculus作為認証提供者很容易,可以在幾秒鐘內從您的Photon應用程序介面完成。 進入一個應用程序的 "管理"頁面,向下滑動到 "認証"部分。 如果您為Oculus添加一個新的認証供應商或編輯一個現有的認証供應商,此為必須的設置:

  • appid:您的Oculus應用程序的ID。
  • appsecret:您的Oculus應用程序機密。

Back To Top

客戶端代碼

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

Back To Top

獲取憑證

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

Back To Top

Unity說明

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

憑證

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

PhotonNetwork.AuthValues = new AuthenticationValues();
PhotonNetwork.AuthValues.UserId = oculusId;
PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Oculus;
PhotonNetwork.AuthValues.AddAuthParameter("userid", oculusId);
PhotonNetwork.AuthValues.AddAuthParameter("nonce", oculusNonce);
// do not set AuthValues.Token or authentication will fail
// connect


To Document Top