This document is about: SERVER 5
SWITCH TO

Photon Oculus認証

サーバー設定

  • 「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とクライアントに提供されるノンスで認証しています。 暗号法では、ノンスは1回のみ使用可能な乱数です。 詳細はこちらを参照してください。

証明書を取得

クライアントはまずOculusにログインし、ノンスを生成する必要があります。 このノンスは、そのクライアントが有効なOculusユーザーであることの証明です。

Oculus SDKはOculusのウェブサイトから取得してください。

Unityのインストラクション

Unity用のOculusプラットフォームSDKをダウンロードして、プロジェクトにインポートしてください。

エディターのメニューバーから「Oculusプラットフォーム」へ進み -> 「設定の編集」でOculus AppIDを入力してください。

以下のコードを使用してログイン済みのユーザーのOculus IDを取得し、ノンスを生成します:

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を送信し、それぞれのキー「userid」と「nonce」を使用して文字列パラメータであるノンスを生成する必要があります。

Back to top