createToken method

Future<CreateTokenResponse> createToken({
  1. required String clientToken,
  2. required String licenseArn,
  3. int? expirationInDays,
  4. List<String>? roleArns,
  5. List<String>? tokenProperties,
})

Creates a long-lived token.

A refresh token is a JWT token used to get an access token. With an access token, you can call AssumeRoleWithWebIdentity to get role credentials that you can use to call License Manager to manage the specified license.

May throw ValidationException. May throw AuthorizationException. May throw AccessDeniedException. May throw RateLimitExceededException. May throw ResourceLimitExceededException. May throw ServerInternalException. May throw ResourceNotFoundException. May throw RedirectException.

Parameter clientToken : Idempotency token, valid for 10 minutes.

Parameter licenseArn : Amazon Resource Name (ARN) of the license. The ARN is mapped to the aud claim of the JWT token.

Parameter expirationInDays : Token expiration, in days, counted from token creation. The default is 365 days.

Parameter roleArns : Amazon Resource Name (ARN) of the IAM roles to embed in the token. License Manager does not check whether the roles are in use.

Parameter tokenProperties : Data specified by the caller to be included in the JWT token. The data is mapped to the amr claim of the JWT token.

Implementation

Future<CreateTokenResponse> createToken({
  required String clientToken,
  required String licenseArn,
  int? expirationInDays,
  List<String>? roleArns,
  List<String>? tokenProperties,
}) async {
  ArgumentError.checkNotNull(clientToken, 'clientToken');
  _s.validateStringLength(
    'clientToken',
    clientToken,
    0,
    60,
    isRequired: true,
  );
  ArgumentError.checkNotNull(licenseArn, 'licenseArn');
  _s.validateStringLength(
    'licenseArn',
    licenseArn,
    0,
    2048,
    isRequired: true,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSLicenseManager.CreateToken'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'ClientToken': clientToken,
      'LicenseArn': licenseArn,
      if (expirationInDays != null) 'ExpirationInDays': expirationInDays,
      if (roleArns != null) 'RoleArns': roleArns,
      if (tokenProperties != null) 'TokenProperties': tokenProperties,
    },
  );

  return CreateTokenResponse.fromJson(jsonResponse.body);
}