generateToken method
- String account, {
- GenerateTokenRequest? generateTokenRequest,
Generate a token
Generate a new token resource for a user, using the user's email and password. Keygen does not store your tokens for security reasons. After a token is generated, it cannot be recovered if lost. The token will need to be revoked if lost, and a new token should be generated. Alternatively, the existing token can be regenerated (rolled). By default, user tokens expire in 2 weeks, and admin tokens do not expire. A custom expiry may be provided in the token generate request. If the user does not have a password, a token must be generated via the user's token relationship To generate a token for a product, see the product token relationship. To generate a license token, see the license token relationship.
Parameters:
-
String account (required): The identifier (UUID) or slug of your Keygen account.
-
GenerateTokenRequest generateTokenRequest:
Implementation
Future<GenerateTokenResponse?> generateToken(String account, { GenerateTokenRequest? generateTokenRequest, }) async {
final response = await generateTokenWithHttpInfo(account, generateTokenRequest: generateTokenRequest, );
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
// When a remote server returns no body with a status of 204, we shall not decode it.
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
// FormatException when trying to decode an empty string.
if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'GenerateTokenResponse',) as GenerateTokenResponse;
}
return null;
}