Get a token that says who's playing a game
curl --request POST \
--url https://patch.gg/api/v1/games/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"project": "mira/lantern-run",
"release": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({project: 'mira/lantern-run', release: '3c90c3cc-0d44-4b50-8888-8dd25736052a'})
};
fetch('https://patch.gg/api/v1/games/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://patch.gg/api/v1/games/token"
payload = {
"project": "mira/lantern-run",
"release": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"token": "<string>",
"expires_at": "<string>",
"player": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"handle": "mira",
"name": "<string>",
"picture": "<string>"
},
"game": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"handle": "mira/lantern-run"
}
}{
"error": {
"code": "version_exists",
"message": "<string>",
"details": "<unknown>"
}
}{
"error": {
"code": "version_exists",
"message": "<string>",
"details": "<unknown>"
}
}{
"error": {
"code": "version_exists",
"message": "<string>",
"details": "<unknown>"
}
}{
"error": {
"code": "version_exists",
"message": "<string>",
"details": "<unknown>"
}
}Games
Get a token that says who's playing a game
The play page asks for one for the game it plays and hands it to the game (window.patch), so the game’s own server can tell who’s playing without asking Patch. Signed-out players get 401: a game asks them to sign in with patch.signIn(). With an API key, it’s a token for the key’s account, for testing a game’s server.
POST
/
games
/
token
Get a token that says who's playing a game
curl --request POST \
--url https://patch.gg/api/v1/games/token \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"project": "mira/lantern-run",
"release": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({project: 'mira/lantern-run', release: '3c90c3cc-0d44-4b50-8888-8dd25736052a'})
};
fetch('https://patch.gg/api/v1/games/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));import requests
url = "https://patch.gg/api/v1/games/token"
payload = {
"project": "mira/lantern-run",
"release": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text){
"token": "<string>",
"expires_at": "<string>",
"player": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"handle": "mira",
"name": "<string>",
"picture": "<string>"
},
"game": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"handle": "mira/lantern-run"
}
}{
"error": {
"code": "version_exists",
"message": "<string>",
"details": "<unknown>"
}
}{
"error": {
"code": "version_exists",
"message": "<string>",
"details": "<unknown>"
}
}{
"error": {
"code": "version_exists",
"message": "<string>",
"details": "<unknown>"
}
}{
"error": {
"code": "version_exists",
"message": "<string>",
"details": "<unknown>"
}
}Body
application/json
Response
A token for the game
A JWT signed with ES256 by a key at GET /v1/games/keys, for 15 minutes. iss is this environment's address (https://patch.gg in production), aud the game's project id, sub the player's id in this game; game, handle, name and picture are claims too.