generateUserToken method
Future<GenerateUserTokenResponse?>
generateUserToken(
- String account,
- String user, {
- GenerateUserTokenRequest? generateUserTokenRequest,
Generate a user token
Generates a new user token resource. User tokens, by default, expire after 2 weeks. Though this can be adjusted via the expiry
attribute. Typically, you'd want to generate a token using the tokens resource, using the user's email and password. But this endpoint can be used by admins to generate a token on a user's behalf. This endpoint is particularly useful for generating tokens for a user without a password, or if you want to manage logins another way, e.g. server-side.
Parameters:
-
String account (required): The identifier (UUID) or slug of your Keygen account.
-
String user (required): The identifier (UUID) or email of the user to generate a token for.
-
GenerateUserTokenRequest generateUserTokenRequest:
Implementation
Future<GenerateUserTokenResponse?> generateUserToken(String account, String user, { GenerateUserTokenRequest? generateUserTokenRequest, }) async {
final response = await generateUserTokenWithHttpInfo(account, user, generateUserTokenRequest: generateUserTokenRequest, );
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), 'GenerateUserTokenResponse',) as GenerateUserTokenResponse;
}
return null;
}