SDK
SDK Dart Null Safety v3.x
2

createApiKey #

Available since 7.1.0
Available since Kuzzle 2.1.0

Creates a new API key for a user.


Copied to clipboard!
Future<Map<String, dynamic>> createApiKey(
      String userId, String description,
      {String? expiresIn, bool? refresh})

Property Type Description
userId
String
User kuid
description
String
API key description
expiresIn
String?

(-1)
Expiration duration
refresh
bool?

(false)
If set to wait_for, Kuzzle will not respond until the API key is indexed

Notes:

  • expiresIn:
    • if a raw number is provided (not enclosed between quotes), then the expiration delay is in milliseconds. Example: 86400000
    • if this value is a string, then its content is parsed by the ms library. Examples: "6d", "10h"
    • if -1 is provided, the token will never expire

Return #

An object containing the newly created API key:

Name Type Description
_id
String
ID of the newly created API key
_source
Map<String, dynamic>
API key content

The API key content has the following properties:

Name Type Description
userId
String
User kuid
expiresAt
int
Expiration date in UNIX micro-timestamp format (-1 if the token never expires)
ttl
int
Original TTL
description
String
API key description
token
String
Authentication token associated with this API key

The authentication token token will never be returned by Kuzzle again. If you lose it, you'll have to delete the API key and recreate a new one.

Usage #

Copied to clipboard!
final result = await kuzzle.security.createApiKey(
  'john.doe',
  'Sigfox API key');
  /*
  {
    _id: '-fQRa28BsidO6V_wmOcL',
    _source: {
      description: 'Sigfox API key',
      userId: 'john.doe',
      expiresAt: -1,
      ttl: -1,
      token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJqb2huLmRvZSIsImlhdCI6MTU3ODA0OTMxMn0.XO_keW6EtsCGmPzxVJCChU9VREakEECDGg-N5lhCfF8'
    }
  }
  */