This document is about: SERVER 5
SWITCH TO

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

Server Configuration

  • Open "deploy\NameServer\bin\NameServer.xml.config".
  • Make sure CustomAuth is enabled, Enabled needs to be true.
  • Optionally set AllowAnonymous to true or false depending on your needs. We recommend setting it to false.
  • Set AuthenticationType to "3" which is the code for VIVEPORT authentication provider type.
  • Choose any name you want, we used "VIVEPORT" for this example but you can change it.
  • Leave "AuthUrl" empty as it's required but we don't need it as the authentication endpoint is internal.
  • Find below the list of the other VIVEPORT specific mandatroy settings with their description:

XML

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

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.

Back to top