This document details the technical specifications for authorizing access to DATA.BET Widgets. The authorization process utilizes JSON Web Tokens (JWT) as the primary mechanism for granting and managing access.
Before implementing the authorization, ensure you have obtained secret id and secret key from the DATA.BET Integration Manager.
Authorization
To authorize your users to access the Widgets, you must provide a JWT as the token attribute of the databet-widgetcomponent.
JWT structure
The JWT adheres to the standard JWT structure and consists of three parts:
Header. Contains information about the token type (JWT) and the signing algorithm (HS256).
Playload. Contains 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 your secret key ID 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. It must be unique for each partner's user, but it is not required to be an internal identifier. (consider symmetric encryption, hashing or using external ids). For non-authenticated users, provide empty string (sub: "").
paywall_passed (boolean) - Indicates whether the user has passed the paywall check. Contact DATA.BET Integration Manager for details.
Warning
A token grants access only to a single sports event event_id accessed from ip until the expiration time exp.
Generating a token
Provided we have the following secret:
id
key
cpb2jhmcgi1ngarccrmg
J08PuNVKmF8El2zxFIBRydQU2K0rQi6z
Here is the payload we want to include in the token:
Key
Value
event_id
30c1d59e-49eb-42cf-bb6a-6684aa92d4c8
ip
1.2.3.4
sub
abcdef123456
Let us 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 do not 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();}}