searchApiKeys #
Available since Kuzzle 2.1.0
Searches for a user API keys.
Available since change-me
This method also supports the Koncorde Filters DSL to match documents by passing the lang
argument with the value koncorde
.
Koncorde filters will be translated into an Elasticsearch query.
Koncorde bool
operator and regexp
clause are not supported for search queries.
Future<SearchResult> searchApiKeys(String userId, Map<String, dynamic> query, {int? from, int? size, String? lang})
Property | Type | Description |
---|---|---|
userId | String | User kuid |
query | Map<String, dynamic> | Search query |
from | int? ( 0 ) | Offset of the first document to fetch |
size | int? ( 10 ) | Maximum number of documents to retrieve per page |
lang | String? | Specify the query language to use. By default, it's elasticsearch but koncorde can also be used. Available since change-me |
query #
The search query to apply to API keys content, using ElasticSearch Query DSL or the Koncorde Filters DSL syntax.
If left empty, the result will return all available API keys for the user.
Returns #
Returns a SearchResult object.
Usage #
With the ElasticSearch Query DSL syntax.
await kuzzle.security.createApiKey(
'john.doe',
'Sigfox API key');
await kuzzle.security.createApiKey(
'john.doe',
'LoRa 6 month API key', expiresIn: '6m');
await kuzzle.security.createApiKey(
'john.doe',
'LoRa permanent API key', refresh: true);
final result = await kuzzle.security.searchApiKeys('john.doe', {
'match': {
'description': 'LoRa'
}
});
print(result);
/*
{
"total": 2,
"hits": [
{
"_id": "znEwbG8BJASM_0-bWU-q",
"_source": {
"description": "LoRa permanent API key",
"userId": "john.doe",
"expiresAt": -1,
"ttl": -1
}
},
{
"_id": "zXEwbG8BJASM_0-bWU-q",
"_source": {
"description": "LoRa 1 year API key",
"userId": "john.doe",
"expiresAt": 31557600000,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl": 360000
}
}
]
}
*/
print('Found ${result.total} API keys matching "LoRa"');
With the Koncorde Filters DSL syntax.
await kuzzle.security.createApiKey(
'john.doe',
'Sigfox API key');
await kuzzle.security.createApiKey(
'john.doe',
'LoRa 6 month API key', expiresIn: '36000');
await kuzzle.security.createApiKey(
'john.doe',
'LoRa permanent API key', refresh: true);
final result = await kuzzle.security.searchApiKeys('john.doe', {
'equals': {
'ttl': 36000
}
}, lang: 'koncorde');
print(result);
/*
{
"total": 2,
"hits": [
{
"_id": "znEwbG8BJASM_0-bWU-q",
"_source": {
"description": "LoRa permanent API key",
"userId": "john.doe",
"expiresAt": -1,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl": -1
}
},
{
"_id": "zXEwbG8BJASM_0-bWU-q",
"_source": {
"description": "LoRa 1 year API key",
"userId": "john.doe",
"expiresAt": 31557600000,
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6",
"ttl": 360000
}
}
]
}
*/
print('Found ${result.total} API key.');
Edit this page on Github(opens new window)