LogoLogo
DocumentationWebsiteCommunityPortal
  • Get Started
    • Quickstart
    • Tutorials
    • Wizards
  • Features
    • Release Notes
      • 2024
        • 04-05 Apr Update
        • 03-27 Mar Update
        • 02-07 Feb Update
        • 01-23 Jan Update
        • 01-05 Jan Update
      • 2023
        • 12-18 Dec Update
        • 11-30 Nov Update
        • 10-30 Oct Update
        • 10-04 Oct Update
        • 09-18 Sep Update
        • 09-11 Sep Update
        • 08-28 Aug Update
        • 08-14 Aug Update
        • 07-23 July Update
        • 07-14 July Update
        • 06-16 June Update
        • 06-6 June Update
        • 05-16 May Update
        • 03-31 Mar Update
        • 03-16 Mar Update
        • 03-10 Mar Update
        • 02-07 Feb Update
        • 01-24 Jan Update
        • 01-10 Jan Update
      • 2022
        • 12-08 Dec Update
        • 11-13 Nov Update
        • 11-07 Nov Update
        • 10-26 Oct Update
        • 10-14 Oct Update
        • 10-01 Oct Update
        • 08-26 Aug Update
        • 08-02 Aug Update
        • 07-01 July Update
        • 06-08 June Update
        • 05-20 May Update
        • 05-05 May Update
        • 04-25 Apr Update
        • 02-11 Feb Update
        • 01-28 Jan Update
        • 01-10 Jan Update
      • 2021
        • 12-10 Dec Update
        • 12-01 Dec Update
        • 11-26 Nov Update
        • 11-17 Nov Update
        • 11-12 Nov Update
        • 11-09 Nov Update
        • 11-02 Nov Update
        • 10-26 Oct Update
        • 10-21 Oct Update
        • 10-14 Oct Update
        • 09-27 Sep Update
        • 08-31 Aug Update
        • 07-20 July Update
        • 07-02 July Update
        • 06-31 June Update
  • Metaverse
    • Building
      • Portal
        • Team Members
        • Defining Global Variables
      • Editor
        • File Manager
          • Selecting a file
          • Sketchfab Integration
        • Placement in 3D Space
        • Project Settings
          • Preferences
          • Branding
          • Collaborators
          • Menu
          • Variables in Settings
          • Lead Generation
          • Tour Mode
          • Advanced
          • E-Commerce in Settings
        • Preview
          • Headset Testing - WebXR Emulator
        • Viewport Properties
        • Editor Keyboard Shortcuts
      • Scenes
        • 3D Scene
          • Avatar System
          • Colliders
          • Zones
          • Lights
        • 360 Scene
        • Orbit Scene
      • Elements
        • Image
        • Video
        • Audio
        • GIF
        • Text to Speech
        • Character
        • Character AI
        • Actionbar
        • Timer
        • Polygon
        • Linked Popups
        • Variants
      • Rules
        • Shared Rules
        • How Rules Work
        • Number Variable Rules
        • String Variable Rules
        • Boolean Variable Rules
      • Variables
        • Autogenerated Variables
        • String Substitution
        • Capturing User Input
      • Build FAQs
    • Publishing
      • URL or QR Code
      • Embed on your Website
      • Full-Page HTML
      • Embedding within Apps
        • Android Embed
        • React Native Embed
      • Export as SCORM package
      • Authentication
        • SSO
        • Password With Expiry
        • Email with OTP
        • Custom List
        • Token
        • Load from another Experience
      • Publishing FAQs
      • Private Cloud Deployment
    • Multiplayer
      • Host Mode
      • Broadcast Mode
      • Voice Chat
      • Text Chat
      • Video Chat
      • Screenshare
      • Comments
      • Share Reactions
      • Notifications
      • Troubleshooting webcam and microphone
    • Analytics
      • Advanced Analytics
      • Leaderboard
      • Viewer Sessions
    • Integrations
      • GMetri with SCORM
        • Embed a SCORM package in a GMetri experience
      • Live Stream on GMetri
        • Live Stream Zoom on YouTube
        • Live Stream Zoom on Vimeo
          • Zoom Setup
      • E-Commerce with GMetri
        • Shopify Integration
        • WooCommerce Integration
        • Custom Integration
        • Using an E-Commerce Plugin
      • Adding a Chatbot
      • Sending data to GMetri Deployment
    • Viewing
      • Avatars
      • First/Third Person
      • Concurrency
      • Oculus Controls
      • Viewer Keyboard Shortcuts
      • IT Permissions
        • Whitelisting for Viewing Experiences
        • Whitelisting for Editing Experiences
        • Whitelisting for Analytics
        • Subprocessors
    • GMetri SDK
      • GMetri Player
      • GMetri SDK APIs
        • Project
        • Deployment
        • File
        • Viewer Group
      • GMetri Webhooks
      • API Token
      • Examples
  • Guidelines/Compatibility
    • Guidelines
      • Content Creation Guidelines
        • XR Experience Storyboard
        • 360 Degree Video Shoots
        • Avatars vs Characters
        • Designing 3D Models for Immersive VR mode
      • Asset Guidelines
        • 3D Models
          • Export GLB/GLTF from 3DS Max
          • Export GLB/GLTF from Blender
        • 360 Pano Images Render
        • Resources for Assets
        • Asset FAQs
        • Image Aspect Ratio
      • Experience Optimizations
        • Scene Optimizations
          • Performance Monitor
        • Image Optimizations
        • Audio Optimizations
        • Video Optimizations
        • 3D Model Optimizations
      • Workflows
        • Green Screen
          • Apply Green Screen to Videos
          • Accurate Color Selection
        • QR Code Scanner
        • Adding Sprites
        • Adding Background Music & Persistent Logo
        • EmbedHTML Snippets
    • Compatibility
      • Platform Requirements - Viewer
      • Platform Compatibility Matrix
      • Supported File Formats
      • Supported Browsers
      • Capture Network and Console Logs from Chrome Browser
    • Limitations
      • iOS Limitations
      • VR Mode Limitations
  • Platform
    • Billing
    • Platform FAQs
    • Security
    • Legal
Powered by GitBook
On this page
  • Creating a Jwt token for your experience:​
  • Jwt Payload​
  • Creating Jwt tokens on the web​
  • Creating Jwt tokens in a java app​
  • Creating Jwt tokens in an android app​

Was this helpful?

Edit on GitHub
Export as PDF
  1. Metaverse
  2. Publishing
  3. Authentication

Token

PreviousCustom ListNextLoad from another Experience

Last updated 4 months ago

Was this helpful?

This option allows to generate automatic login tokens to login the viewers. A great way to use this feature is to autogenrate the login tokens via an API and create limited time login links.

To generate a token, create a new viewer group and select the token login method. When you select this, you will be shown a signing key, copy this signing key. This will be used to generate the login tokens.

To generate a login token, we create a Jwt token. This login token will be appended to the experience link.

The final url will look like this:

<deployment-link>?token=<generate-jwt-token>

An example url:

https://view.gmetri.com/v4/game/safehands_v2?token=34fhdf7asbfdsa09in2m1od.09u0dfa8nfdjajkbfe8uih32rjn.908ufdbsahbjfd9sabjhfdu

Creating a Jwt token for your experience:​

JSON Web Token (Jwt) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. A typical Jwt consists of three parts separated by dots (.), which are header, payload and signature. Therefore, a JWT typically looks like the following. xxxxx.yyyyy.zzzzz. More information about Jwts can be found .

Jwt Payload​

This information is required to correctly identify a viewer on GMetri experiences. The payload for the JWT is shown below (the optional fields can be set as per requirement):

{ 
  "identifier" (required): "John001",  
  "first_name" (optional): "John",
  "last_name" (optional): "Doe",
  "phone_num" (optional): "+1 000 000 000"
}

identifier is the unique key by which you identify your viewers.

Creating Jwt tokens on the web​

We recommend using npm package jsonwebtoken to generate jwt tokens on the web (both on server and browser)

An example of generating a Jwt token in node.js:

const jwt = require('jsonwebtoken');

function generateJwt() {
  const payload = {
    identifier: 'John001', // A unique identifier for your user
    first_name: 'John'  
  };
  const apiSecretkey = "<your api secret key>";
  const token = jwt.sign(payload, apiSecretkey);
  return token;
}

Creating Jwt tokens in a java app​

  import java.security.Key;
  import io.jsonwebtoken.Jwts;
  import io.jsonwebtoken.security.Keys;
  
  String createJwt(String url, String identifier, String apiSecret) {
    JSONObject obj = new JSONObject();
    obj.put("identifier", identifier);
    Key key = Keys.hmacShaKeyFor(apiSecret.getBytes());
    String jwt = Jwts.builder().setPayload(obj.toString()).signWith(key).compact();    
    return url + "?token=" + jwt;  
  }
  
  // url is the link from deployment section sssss  
  String finalUrl = createJwt(url, <unique identifier>, <your api secret key>);

Creating Jwt tokens in an android app​

In your android experience, add the required dependencies for Chrome Custom Tabs and Jwt. Following is an example of gradle build dependencies:

dependencies {    
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation 'com.android.support:appcompat-v7:26.1.0'
  implementation 'com.android.support:customtabs:26.1.0'
  api 'io.jsonwebtoken:jjwt-api:0.11.0'    
  runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.0'    
  runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.11.0') {        
    exclude group: 'org.json', module: 'json' //provided by Android natively    
  }
}

Information on how to install dependencies for other build systems are in the links below:

The className ChromeCustomTabsJwt.java implements two public methods:

  1. initialize(String viewerIdentifier, String apiKey, String url, Context context)

  2. launch()

Arguments:

  1. viewerIdentifier - This is a JSON string containing information for the viewer

  2. apiKey - A unique key generated for GMetri experiences.

  3. url - Url of the experience

  4. context - Context of your activity (this)

An example implementation of the above classes:

  ChromeCustomTabsJwt chromeCustomTabs = new ChromeCustomTabsJwt();
  JSONObject obj = new JSONObject();  
  try {    
    obj.put("identifier", "test@example.com");  
  } catch (JSONException e) {    
    e.printStackTrace();  
  }  
  
  String apiKey = "your_secret_api_key";  
  String url = "url_to_open";  
  chromeCustomTabs.initialize(obj.toString(), apiKey, url, this);  
  chromeCustomTabs.launch();

To run GMetri experiences inside android apps, we recommend an implementation of Chrome Custom Tabs API. Detailed information on how to setup an android experience with Chrome Custom Tabs can be found in this

From this , copy two files: ChromeCustomTabsJwt.java and ServiceConnectionCallback.java into your android experience. These files together provide the interface for chrome custom tabs to run GMetri experiences.

To add more fields to viewerIdentifier JSON object refer to the section.

here
experience
Chrome custom tabs
JWT
experience
payload