This document is about: SERVER 5
SWITCH TO

Photon VIVEPORT Authentication

概述

添加VIVEPORT作為Photon認証供應商很容易。

您將需要一個VIVEPORT的AppId和一個VIVEPORT的AppSecret。請聯系VIVEPORT內容團隊(store@viveport.com)申請AppSecret。由於這一個步驟不是自動化的,所以要提前開始這個過程。

伺服器配置

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

XML

  <CustomAuth Enabled="true" AllowAnonymous="false">
    <AuthProviders>
      <AuthProvider Name="VIVEPORT"
                    AuthenticationType="10"
                    AuthUrl=""
                    appid="Replace with ID of your VIVEPORT app"
                    appsecret="Replace with Secret for your VIVEPORT app." />
    </AuthProviders>
  </CustomAuth>

客戶端代碼

Photon用一個臨時令牌來驗証VIVEPORT的用戶,該令牌由VIVEPORT API提供。

下載VIVEPORT SDK並從壓縮包中導入Unity包到您的項目中。

獲取VIVEPORT令牌

在連接到Photon之前,客戶端必須登錄到VIVEPORT並獲得一個會話令牌。 下面的工作流程是一個基本步驟的總結。整個代碼可以在VIVEPORT SDK中的VIVEPORTDemo.cs中看到。

如同VIVEPORT的慣例,第一步是用VIVEPORT AppId啟動API。

C#

//...

Api.Init(InitStatusHandler, APP_ID);

//...

private static void InitStatusHandler(int nResult)
{
    if (nResult == 0)
    {
        bInit = true;
        bIsReady = false;
        ViveSessionToken = string.Empty;
        bArcadeIsReady = false;
        Viveport.Core.Logger.Log("InitStatusHandler is successful");
    }
    else
    {
        // Init error, close your app and make sure your app ID is correct or not.
        bInit = false;
        Viveport.Core.Logger.Log("InitStatusHandler error : " + nResult);
    }
}

//...

在初始化之後(例如在InitStatusHandler()中),檢查令牌是否已經准備好。調用Viveport.Token.IsReady

C#

//...

Token.IsReady(IsTokenReadyHandler);

//...

private static void IsTokenReadyHandler(int nResult)
{
    if (nResult == 0)
    {
        bTokenIsReady = true;
        Viveport.Core.Logger.Log("IsTokenReadyHandler is successful");
    }
    else
    {
        bTokenIsReady = false;
        Viveport.Core.Logger.Log("IsTokenReadyHandler error: " + nResult);
    }
}

//...

現在客戶端可以得到一個會話令牌,它是一個有效的VIVEPORT用戶的証明。

C#

//...

Token.GetSessionToken(GetSessionTokenHandler);

//...

private static void GetSessionTokenHandler(int nResult, string message)
{
    if (nResult == 0)
    {
        Viveport.Core.Logger.Log("GetSessionTokenHandler is successful, token:" + message);

        // Photon:
        // With the viveport token, we can set the auth values for Photon and connect / auth.
        // We store the token for later use.
        ViveSessionToken = message;
    }
    else
    {
        if (message.Length != 0)
        {
            Viveport.Core.Logger.Log("GetSessionTokenHandler error: " + nResult + ", message:" + message);
        }
        else
        {
            Viveport.Core.Logger.Log("GetSessionTokenHandler error: " + nResult);
        }
    }
}

憑證

ViveSessionToken是客戶端在Photon VIVEPORT認証中唯一需要的值。

請確保使用CustomAuthenticationType.Viveport並設置 "userToken "AuthParameter。

Back to top