Signed Players
Long-term memory belongs to the playerId your backend sends. With signed players required, LoreMind recalls and saves a player's memories only when the request also carries a short-lived token your backend signed for that player. Anyone who gets hold of your Server Key still can't read or change a player's memories without your signing secret.
Signed players are off until you turn them on. Requests that don't ask for memory are not affected.
How It Works
- Your game signs the player in with your backend, as it does today.
- For each memory request, your backend signs a token for that
playerIdwith your project's signing secret. - Your backend sends the token as
playerAssertionin the request body. - LoreMind checks the token. Without a valid one, the request is refused with
403, and nothing is charged.
Keep the signing secret on your backend only, like your Server Key. Never put it in a game build.
Turn It On
- In the dashboard, open your project and go to Settings, then Signed Players. Only team owners and admins can change these settings.
- Click Create Secret and copy the secret. It is shown only once.
- Store it on your backend, in an environment variable or a secrets manager.
- Update your backend to send
playerAssertionwith every memory request (see below), and deploy it. - Turn on Require Signed Players.
Do step 5 only after your backend sends tokens: from then on, memory requests without a valid token are refused.
Signing a Player
The token is a standard JWT signed with HS256. The key is the signing secret exactly as shown, as UTF-8 bytes.
| Claim | Required | Value |
|---|---|---|
sub | Yes | The request's playerId, exactly |
exp | Yes | When the token expires, in seconds since the Unix epoch. It must still be in the future when the request arrives, and at most 1 hour away |
nbf | No | If present, the token is refused before this time |
The header's alg must be HS256; tokens signed with any other algorithm are refused. Other claims are ignored.
Make a new token for each request and keep it short-lived: 5 minutes is plenty. Tokens that expire more than 1 hour after the request arrives are refused.
LoreMind allows up to 30 seconds of difference between its clock and your backend's, for both exp and nbf. Keep your backend's clock in sync.
Node.js (jose)
import { SignJWT } from 'jose';
const key = new TextEncoder().encode(process.env.LOREMIND_PLAYER_SIGNING_SECRET);
const playerAssertion = await new SignJWT({})
.setProtectedHeader({ alg: 'HS256' })
.setSubject(playerId)
.setExpirationTime('5m')
.sign(key);Python (PyJWT)
import os
import time
import jwt
player_assertion = jwt.encode(
{"sub": player_id, "exp": int(time.time()) + 300},
os.environ["LOREMIND_PLAYER_SIGNING_SECRET"],
algorithm="HS256",
)C# (System.IdentityModel.Tokens.Jwt)
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Microsoft.IdentityModel.Tokens;
var key = new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(Environment.GetEnvironmentVariable("LOREMIND_PLAYER_SIGNING_SECRET")!));
var token = new JwtSecurityToken(
claims: new[] { new Claim(JwtRegisteredClaimNames.Sub, playerId) },
expires: DateTime.UtcNow.AddMinutes(5),
signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256));
var playerAssertion = new JwtSecurityTokenHandler().WriteToken(token);Sending the Token
Add playerAssertion to the POST /npc/interact body, next to playerId:
curl -X POST https://loremind.peekgames.dev/api/loremind/v1/npc/interact \
-H "Authorization: Bearer sk_server_your_key" \
-H "Content-Type: application/json" \
-d '{
"text": "Do you remember me?",
"entityMindId": "em_abc123",
"playerId": "steam_76561198012345678",
"memory": { "retrieve": true },
"playerAssertion": "eyJhbGciOiJIUzI1NiJ9..."
}'Sign the playerId your backend verified for the signed-in player, never one the game client sent. If your game uses the Unity SDK with your own backend, your backend adds playerAssertion to the request body before it forwards the request to LoreMind.
While signed players are not required, LoreMind accepts playerAssertion and ignores it, so you can deploy your backend change first.
Errors
Both errors are 403, and the request is not charged.
| Code | Cause | What to do |
|---|---|---|
PLAYER_ASSERTION_REQUIRED | A memory request (memory.retrieve: true) came without playerAssertion | Sign the player and send the token with the request |
PLAYER_ASSERTION_INVALID | The token is malformed, expired, valid for more than 1 hour, signed with another secret or algorithm, or its sub is not the request's playerId | Sign a new token for this playerId with the current signing secret |
{
"error": "Player assertion required",
"code": "PLAYER_ASSERTION_REQUIRED",
"message": "This project requires signed players for memory requests. Send playerAssertion: a token your server signs for this playerId with the project signing secret."
}Don't retry either error unchanged: the same request fails the same way.
Replacing the Secret
Replace Secret creates a new signing secret, and tokens signed with the old one stop working at once. While signed players are required, memory requests are refused until your backend signs with the new secret. To switch without refused requests:
- Turn off Require Signed Players.
- Click Replace Secret, then put the new secret on your backend and deploy it.
- Turn Require Signed Players back on.
Replace the secret right away if it may have been exposed.
Turning It Off
Turn off Require Signed Players at any time. Memory requests then work without a token, as before.
Testing
The Playground's test players are not affected. Memory requests sent straight from the Unity Editor with a Server Key carry no token, so while signed players are required, those requests are refused. Test memory in the Playground, or turn signed players on once your backend signs players.
Next Steps
- Long-Term Memory - How memory works and what makes a good
playerId - Server Integration - Production patterns for your backend
- Authentication - Key types, storage and rotation
- Errors & Rate Limits - Every error code