Photon VIVEPORT Authentication

Contents

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 (store@viveport.com) to apply for an AppSecret. As this one step is not automated, start the process ahead of time.

Back To Top

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 (store@viveport.com) to apply for an AppSecret.

Back To Top

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.

Back To Top

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.

//...

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:

//...

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.

//...

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

Back To Top

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.

//...

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

//...

To Document Top