node-jsonwebtoken, a third-party library.
Generate a tenant token with jsonwebtoken
Build the tenant token payload
First, create a set of search rules:uid field to obtain your API key’s UID:
Create tenant token
First, includejsonwebtoken in your application. Next, assemble the token payload and pass it to jsonwebtoken’s sign method:
sign requires the payload, a Meilisearch API key, and an encryption algorithm. Meilisearch supports the following encryption algorithms: HS256, HS384, and HS512.
Your tenant token is now ready to use.
Though this example used
jsonwebtoken, a Node.js package, you may use any JWT-compatible library in whatever language you feel comfortable.Make a search request using a tenant token
After signing the token, you can use it to make search queries in the same way you would use an API key.Next steps
Tenant token payload reference
Detailed reference for all fields in the tenant token payload.
Generate tokens with an SDK
Use a Meilisearch SDK to generate tenant tokens with less manual work.
Generate tokens without any library
Build tenant tokens manually by assembling the JWT header, payload, and signature.