Meilisearch’s tenant tokens are JSON web tokens (JWTs). Their payload is made of three elements: search rules, an API key UID, and an optional expiration date.
Meilisearch’s tenant tokens are JSON web tokens (JWTs). Their payload is made of three elements: search rules, an API key UID, and an optional expiration date.
You can use jwt.io to inspect and debug tenant tokens during development. Paste a token into the tool to view its decoded header, payload, and signature.
Meilisearch applies the filter to all searches made with that tenant token. A token only has access to the indexes present in the searchRules object.A token may contain rules for any number of indexes. Specific rulesets take precedence and overwrite * rules.
Because tenant tokens are generated in your application, Meilisearch cannot check if search rule filters are valid. Invalid search rules throw errors when searching.Consult the search API reference for more information on Meilisearch filter syntax.
The search rule may also be an empty object. In this case, the tenant token will have access to all documents in an index:
In this example, the user will receive documents from any index starting with medical. This includes indexes such as medical_records and medical_patents:
In this example, the user has access to documents with user_id = 1 for all indexes, except one. When querying medical_records, the user will only have access to published documents:
{ "*": { "filter": "user_id = 1" }, "medical_records": { "filter": "user_id = 1 AND published = true", }}
Query the get one API key endpoint to obtain an API key’s UID.The UID must indicate an API key with access to the search action. A token has access to the same indexes and routes as the API key used to generate it.Avoid exposing API keys and always generate tokens on your application’s back end.
If an API key expires, any tenant tokens created with it will become invalid. The same applies if the API key is deleted.
A token’s expiration date cannot exceed its parent API key’s expiration date.Setting a token expiry date is optional, but highly recommended. Tokens without an expiry date remain valid indefinitely and may be a security liability.
The only way to revoke a token without an expiry date is to delete its parent API key.