This document details the technical specifications for authorizing access to the Widget API. The authorization process utilizes JSON Web Tokens (JWT) as the primary mechanism for granting and managing access. Partners are provisioned with secret ID-key pairs, which they use to issue JWTs to their users for specific sport matches.
Authorization
To authorize access to the Widget API, you must provide the JWT as the token attribute of the widget component.
JWT Structure
JWTs used for authorization adhere to the standard JWT structure and consist of three parts:
Header: Contains information about the token type (JWT) and the signing algorithm used (HS256).
Payload: Contains the claims, which are statements about an entity (typically, the user) and additional data.
Signature: A string created by encrypting the header and payload with the secret key, used to verify the token's authenticity.
Header
The header consists of two parts:
typ (string) - the type of the token;
alg (string) - the algorithm used to sign the token.
Payload
The payload must contain the following claims. Adding additional ones will not affect the token's validity.
key_id (string) - Unique identifier of the Partner's secret key used to sign the JWT;
exp (number) - Standard claim that defines the expiration time of the token. The value is a Unix timestamp representing the number of seconds since the Unix epoch;
event_id (string) - Unique identifier for the specific sports event for which the token is valid;
ip (string) - IPv4 address of the user to whom the token was issued;
sub (string) - User identifier, allowing the Partner to identify the specific user associated with the token. Must be unique for each Partner's user, but not necessarily an internal identifier (consider symmetric encryption, hashing or using external ids).
JWT Example
Provided we have the following secret:
id
key
cpb2jhmcgi1ngarccrmg
J08PuNVKmF8El2zxFIBRydQU2K0rQi6z
Here is the payload we want to include into the token:
Key
Value
event_id
30c1d59e-49eb-42cf-bb6a-6684aa92d4c8
ip
1.2.3.4
sub
abcdef123456
We want to issue a token valid until Wed May 01 2024 05:00:00 GMT+0000.
Here is how the Header and Payload would look (raw):
Most of the time, developers won't need to implement the JWT signing algorithm from scratch. Instead, they can use libraries that provide this functionality.
Here are some examples of how to generate JWTs in different programming languages:
usingSystem;usingSystem.IdentityModel.Tokens.Jwt;usingMicrosoft.IdentityModel.Tokens;usingSystem.Security.Claims;usingSystem.Text;publicclassJwtGenerator{publicstaticstringGenerateToken(){varsecretKeyId="cpb2jhmcgi1ngarccrmg";varsecretKey="J08PuNVKmF8El2zxFIBRydQU2K0rQi6z";varexpirationTime=DateTime.UtcNow.AddHours(24);// Expiration in 24 hoursvarclaims=new[]{newClaim("key_id",secretKeyId),newClaim("exp",((DateTimeOffset)expirationTime).ToUnixTimeSeconds().ToString()),newClaim("event_id","30c1d59e-49eb-42cf-bb6a-6684aa92d4c8"),newClaim("ip","1.2.3.4"),newClaim("sub","abcdef123456"),};varsecurityKey=newSymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey));varcredentials=newSigningCredentials(securityKey,SecurityAlgorithms.HmacSha256);vartokenDescriptor=newSecurityTokenDescriptor{Subject=newClaimsIdentity(claims),Expires=expirationTime,SigningCredentials=credentials};vartokenHandler=newJwtSecurityTokenHandler();vartoken=tokenHandler.CreateToken(tokenDescriptor);returntokenHandler.WriteToken(token);}}
1 2 3 4 5 6 7 8 9101112131415161718192021222324
importio.jsonwebtoken.Jwts;importio.jsonwebtoken.security.Keys;importjava.security.Key;importjava.util.Date;publicclassJwtGenerator{publicstaticStringgenerateToken(){StringsecretKeyId="cpb2jhmcgi1ngarccrmg";StringsecretKey="J08PuNVKmF8El2zxFIBRydQU2K0rQi6z";Keykey=Keys.hmacShaKeyFor(secretKey.getBytes());// Generate signing keyDateexpirationTime=newDate(System.currentTimeMillis()+24*60*60*1000);// 24 hoursreturnJwts.builder().claim("key_id",secretKeyId).claim("exp",expirationTime.getTime()/1000)// Convert to seconds.claim("event_id","30c1d59e-49eb-42cf-bb6a-6684aa92d4c8").claim("ip","1.2.3.4").claim("sub","abcdef123456").signWith(key).compact();}}