---
title: "JWT Authentication"
canonical_url: "https://docs.sportradar.com/resources/virtual-stadium/docs/gettingStarted/authentication"
markdown_url: "https://docs.sportradar.com/resources/virtual-stadium/docs/gettingStarted/authentication.md"
last_updated: "2026-08-11T09:00:08Z"
---

# JWT Authentication

Virtual Stadium uses JWT tokens to authenticate users and control access to features. The general JWT setup (key generation, standard claims, signing, and key rotation) is documented in the Engagement Tools [JWT guide](https://docs.sportradar.com/resources/widgets.md). This page covers Virtual Stadium–specific claims and how to pass the token when initializing Virtual Stadium.

## Overview

To authenticate users with Virtual Stadium:

1. Generate an RSA key pair and share your public key with Sportradar
2. Sign JWT tokens server-side using your private key, with scope `vs` and the [Virtual Stadium-Specific Claims](#virtual-stadium-specific-claims) below
3. Pass the token when initializing Virtual Stadium

***

## RSA Key Generation

Generate a pair of RSA keys using the OpenSSL toolkit:

```bash
# Generate private key (2048-bit RSA)
openssl genrsa -out rsa-private.pem 2048

# Extract public key from private key
openssl rsa -in rsa-private.pem \
  -pubout \
  -outform PEM \
  -out rsa-public.pem
```

### `rsa-private.pem`

Keep this secure on your backend server and use it to sign tokens.

### `rsa-public.pem`

Send this file to Sportradar for token validation setup.

**Optional: Verify the Generated Keys**

```bash
# View private key
openssl rsa -in rsa-private.pem -text -noout

# View public key
openssl rsa -in rsa-public.pem -pubin -text -noout
```

Example public key format (`rsa-public.pem`):

```plaintext
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
...
-----END PUBLIC KEY-----
```

> **Security Best Practices**
>
> - Never expose your private key (`rsa-private.pem`) in client-side code, version control, or logs
> - Never share private keys with third parties
> - Store private keys in secure key management systems or environment variables
> - Never generate or sign JWT tokens in client-side JavaScript
> - Rotate keys periodically
> - Generate separate key pairs for each environment (dev, staging, production)

> **Next Action**
>
> Send the `rsa-public.pem` file to your Sportradar sales or client setup representative. They will configure the system to validate tokens signed with your private key.

> **Non-Production Environments**
>
> If you need development or non-production JWTs, tell client setup which environment the public key is for (`prod`, `nonprod`, or `dev`), and put the same value in the `env` claim on JWTs signed with that key. Production-only flows can omit `env`; it defaults to production behavior.

***

## The Token Object

JSON Web Token (JWT) is an open standard ([RFC 7519](https://tools.ietf.org/html/rfc7519)) 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.

Learn more about [JWT structure](https://jwt.io/introduction#what-is-json-web-token-structure).

### Header

Algorithm and token type

### Payload

Claims (identity, scope, product data)

### Signature

RS256 signature over header + payload

```json
{
  "header": {
    "alg": "RS256",
    "typ": "JWT"
  },
  "payload": {
    "iss": "your-organization",
    "sub": "user123",
    "scope": "vs",
    "iat": 1681718850,
    "apiKey": "your-api-key",
    "displayName": "John Doe",
    "userType": "Normal"
  },
  "signature": "..."
}
```

***

### Token Payload Attributes

#### Standard JWT Claims

All JWT tokens must include these standard claims:

```javascript
{
    iss: '<organization>',
    sub: '<id>',
    scope: 'av' | 'vs' | 'sb' | 'av vs sb',
    iat: 1681718850
}
```

| Claim   | Type              | Description                                                                                                                                                                                                                                                                                                 | Example                                                             |
| ------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| `iss`   | string            | Issuer identifier — identifies the principal that issued the JWT. Typically your organization or application identifier.                                                                                                                                                                                    | `'your-organization'`                                               |
| `sub`   | string            | Unique end-user identifier. Use your system's user ID or a salted hash if you prefer not to expose actual IDs.                                                                                                                                                                                              | `'user_12345'` or `'a3f5b2c8d1e4'`                                  |
| `scope` | string            | Space-separated permissions for this user. Controls access to specific features.<br/>`av` - Enables audio/video stream access in Live Match Tracker.<br/>`vs` - Virtual Stadium access.<br/>`sb` - Bet Concierge access                                                                                     | `'av vs'` for LMT audio/video and Virtual Stadium (space-separated) |
| `iat`   | number            | Token issued-at timestamp in **seconds** since Unix epoch (UTC). Default validity: 16 hours. Most JWT libraries add this automatically.                                                                                                                                                                     | `1681718850`                                                        |
| `exp`   | number (optional) | Expiration timestamp in **seconds** since Unix epoch (UTC). If omitted, defaults to 16 hours after `iat`.                                                                                                                                                                                                   | `1681776450`                                                        |
| `env`   | string (optional) | Which environment the **signing key** is for: `prod`, `nonprod`, or `dev`. Set when you use a non-production key (for example a development-only key pair); tell client setup the same when you submit that key's public key. Omit or leave empty for your production key—then behavior matches **`prod`**. | `'dev'`                                                             |

> **Tip**
>
> The `iat` claim is typically added automatically by JWT libraries. You can also add an `exp` (expiration) claim to set a shorter validity period than the default 16 hours. Shorter token lifespans improve security.

**Standard Claims**

```json
{
  "iss": "your-organization",
  "sub": "user123",
  "scope": "vs",
  "iat": 1681718850,
  "exp": 1681776450
}
```

**Multiple Products**

```json
{
  "scope": "av vs"
}
```

**Calculate Expiration**

```js
// 16 hours from now
const iat = Math.floor(Date.now() / 1000);
const exp = iat + (16 * 60 * 60);

// Token payload
{
  "iat": iat,
  "exp": exp
}
```

***

#### Virtual Stadium-Specific Claims

**`apiKey`** `string` required

Your Virtual Stadium API key provided by Sportradar during onboarding.

***

**`displayName`** `string` required

User's display name shown in the Virtual Stadium interface (visible to other users).

***

**`userType`** `enum` required

User access level. VIP users have highlighted chat messages and special privileges.

Possible enum values:

- `Normal` - Standard user access
- `VIP` - Enhanced user with highlighted messages

> **VIP Users**
>
> VIP users receive enhanced visibility with different design styling. Their chat messages are highlighted to stand out in conversations. For more details, see the [VIP functionality documentation](https://docs.sportradar.com/resources/virtual-stadium/docs/web/widgets/virtualStadium/features/vip.md).

***Virtual Stadium Claims Example:***

```json
{
  "apiKey": "vs_live_abc123xyz789",
  "displayName": "John Doe",
  "userType": "Normal"
}
```

***VIP User Example:***

```json
{
  "apiKey": "vs_live_abc123xyz789",
  "displayName": "Jane Smith",
  "userType": "VIP"
}
```

***

### Complete Token Payload Example

All required claims combined in a single payload object.

***Complete JWT Payload:***

```json
{
  "iss": "your-organization",
  "sub": "user123",
  "scope": "vs",
  "iat": 1681718850,
  "exp": 1681776450,
  "apiKey": "vs_live_abc123xyz789",
  "displayName": "John Doe",
  "userType": "Normal"
}
```

***

## Create a Token

Sign your JWT using the **RS256** algorithm with your private key. Most JWT libraries support RS256 signing.

#### Parameters

**`payload`** `object` required

Token payload containing all required claims (see claim descriptions above).

**`privateKey`** `string` required

Your RSA private key in PEM format.

**`algorithm`** `string` required

Must be `RS256` (RSA signature with SHA-256).

#### Returns

Returns a signed JWT token string that can be used to authenticate with Sportradar widgets and products.

> **Token Security**
>
> - Generate tokens server-side only
> - Create unique tokens for each user session
> - Never share tokens between users
> - Tokens are valid for 16 hours maximum (or until `exp` if specified)
> - Shorter token lifespans improve security

**Node.js**

***Sign JWT Token:***

```javascript
import jwt from "jsonwebtoken";
import fs from "fs";

// Load private key
const privateKey = fs.readFileSync("rsa-private.pem", "utf8");

// Create token with base + Virtual Stadium claims
const token = jwt.sign(
  {
    iss: "your-organization",
    sub: "user123",
    scope: "vs",
    apiKey: "vs_live_abc123xyz789",
    displayName: "John Doe",
    userType: "Normal",
    // iat is added automatically
  },
  privateKey,
  { algorithm: "RS256" },
);

console.log(token);
```

**Python**

***Sign JWT Token:***

```python
import jwt
from datetime import datetime, timedelta

# Load private key
with open('rsa-private.pem', 'r') as key_file:
    private_key = key_file.read()

# Create payload
payload = {
    'iss': 'your-organization',
    'sub': 'user123',
    'scope': 'vs',
    'iat': datetime.utcnow(),
    'exp': datetime.utcnow() + timedelta(hours=16),
    'apiKey': 'vs_live_abc123xyz789',
    'displayName': 'John Doe',
    'userType': 'Normal'
}

# Sign token
token = jwt.encode(
    payload,
    private_key,
    algorithm='RS256'
)

print(token)
```

**Java**

***Sign JWT Token:***

```java
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Date;

// Load private key
byte[] keyBytes = Files.readAllBytes(
    Paths.get("rsa-private.pem")
);
PKCS8EncodedKeySpec spec =
    new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
PrivateKey privateKey = kf.generatePrivate(spec);

// Create token
String token = Jwts.builder()
    .setIssuer("your-organization")
    .setSubject("user123")
    .claim("scope", "vs")
    .claim("apiKey", "vs_live_abc123xyz789")
    .claim("displayName", "John Doe")
    .claim("userType", "Normal")
    .setIssuedAt(new Date())
    .signWith(privateKey, SignatureAlgorithm.RS256)
    .compact();

System.out.println(token);
```

**C#**

***Sign JWT Token:***

```csharp
using System;
using System.IO;
using System.Security.Cryptography;
using Jose;

// Load private key
var privateKeyText = File.ReadAllText(
    "rsa-private.pem"
);
var rsa = RSA.Create();
rsa.ImportFromPem(privateKeyText);

// Create payload
var payload = new Dictionary<string, object>
{
    { "iss", "your-organization" },
    { "sub", "user123" },
    { "scope", "vs" },
    { "iat", DateTimeOffset.UtcNow.ToUnixTimeSeconds() },
    { "apiKey", "vs_live_abc123xyz789" },
    { "displayName", "John Doe" },
    { "userType", "Normal" }
};

// Sign token
string token = JWT.Encode(
    payload,
    rsa,
    JwsAlgorithm.RS256
);

Console.WriteLine(token);
```

**Example Token Output**

```plaintext
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMTIzIiwic2NvcGUiOiJ2cyIsImlhdCI6MTY4MTcxODg1MCwiYXBpS2V5Ijoidi3NfbGl2ZV9hYmMxMjN4eXo3ODkiLCJ1c2VySWQiOiJ1c2VyMTIzIiwiZGlzcGxheU5hbWUiOiJKb2huIERvZSIsInVzZXJUeXBlIjoiTm9ybWFsIn0.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c...
```

***

## Pass JWT to Virtual Stadium

Deliver the signed JWT from your backend to your frontend, then pass it when initializing the Virtual Stadium widget. The `jwt` property is required for authenticated sessions.

```javascript
SIR("addWidget", "#virtual-stadium-container", "virtualStadium", {
  channelId: "your-channel-id",
  jwt: generatedJwtToken,
  // ... other configuration
});
```

For full initialization options, see the [Virtual Stadium Quick Start](https://docs.sportradar.com/resources/virtual-stadium/docs/web/widgets/virtualStadium/quickStart.md).

***

## Key Rotation

Rotate signing keys without service interruption:

1. **Generate a New Key Pair**

   Create a new RSA key pair using the same process as Step 1.

2. **Submit the Public Key**

   Send the new public key to your Sportradar representative.

3. **Wait for Confirmation**

   Sportradar adds the new key to your configuration and notifies you. Both old and new keys work during the transition.

4. **Switch Your Backend**

   Start signing with the new private key, then inform Sportradar when migration is complete so the old public key can be removed.
