This document is about: PUN 2
SWITCH TO

PUN Classic (v1), PUN 2 and Bolt are in maintenance mode. PUN 2 will support Unity 2019 to 2022, but no new features will be added. Of course all your PUN & Bolt projects will continue to work and run with the known performance in the future. For any upcoming or new projects: please switch to Photon Fusion or Quantum.

Photon VIVEPORT Authentication

Overview

Adding VIVEPORT as a Photon Authentication Provider is easy.

You will need a VIVEPORT AppId and a VIVEPORT AppSecret. Contact the VIVEPORT content team ([email protected]) to apply for an AppSecret. As this one step is not automated, start the process ahead of time.

Application Setup

As first step, you should setup VIVEPORT Authentication in the Photon Applications' Dashboard.

Go to the "Manage" page of an application and scroll down to the "Authentication" section.
With one click, you can add or edit the "HTC Vive" authentication provider. You will need:

  • appid: ID of your VIVEPORT app.
  • appsecret: Secret for your VIVEPORT app.

The VIVEPORT AppId can be found in the VIVEPORT Developer Console. Select your application and open the "VIVEPORT Listing" page.
You have to contact the VIVEPORT content team ([email protected]) to apply for an AppSecret.

Client Code

Photon verifies VIVEPORT a user with a temporary token, which is provided by the VIVEPORT API.

Download the VIVEPORT SDK and import the Unity package from the zip into your project.

Get VIVEPORT Token

Before connecting to Photon, the client must to login to VIVEPORT and get a session token.
The following workflow is a summary of the essential steps. The entire code can be seen in VIVEPORTDemo.cs available in the VIVEPORT SDK.

As usual with VIVEPORT, the first step is to init the API with the VIVEPORT AppId.

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

//...

After init (e.g. in InitStatusHandler()), check if the token is ready. Call 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);
    }
}

//...

Now the client can get a session token, which is the proof of a valid VIVEPORT user.

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

Authenticate

The ViveSessionToken is the only value that a client needs for Photon VIVEPORT Authentication.

Make sure to use the CustomAuthenticationType.Viveport and to set the "userToken" AuthParameter.

C#

//...

    if (PhotonNetwork.AuthValues == null)
    {
        PhotonNetwork.AuthValues = new AuthenticationValues();
    }

    PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Viveport;
    PhotonNetwork.AuthValues.AddAuthParameter("userToken", ViveSessionToken);
    // do not set PhotonNetwork.AuthValues.Token or authentication will fail
    if (!PhotonNetwork.ConnectUsingSettings())
    {
        Debug.LogWarning("Could not PhotonNetwork.ConnectUsingSettings(). Check settings.");
    }
    
//...
Back to top