loginOrRefreshWithHttpInfo method

Future<Response> loginOrRefreshWithHttpInfo(
  1. String grantType,
  2. String clientId,
  3. String clientSecret, {
  4. String? username,
  5. String? password,
  6. String? refreshToken,
  7. String? totp,
})

Login or refresh token

Login with username and password, or refreshes the token when refresh token is supplied

Note: This method returns the HTTP Response.

Parameters:

  • String grantType (required):

  • String clientId (required):

  • String clientSecret (required):

  • String username:

  • String password:

  • String refreshToken: Token to refresh the access. Can be used after the first login to refresh the access token without using username and password.

  • String totp: Token for 2FA. If 2FA is enable, the token must not be null.

Implementation

Future<Response> loginOrRefreshWithHttpInfo(
  String grantType,
  String clientId,
  String clientSecret, {
  String? username,
  String? password,
  String? refreshToken,
  String? totp,
}) async {
  // ignore: prefer_const_declarations
  final path = r'/auth/realms/master/protocol/openid-connect/token';

  // ignore: prefer_final_locals
  Object? postBody;

  final queryParams = <QueryParam>[];
  final headerParams = <String, String>{};
  final formParams = <String, String>{};

  const contentTypes = <String>['application/x-www-form-urlencoded'];

  formParams[r'grant_type'] = parameterToString(grantType);
  formParams[r'client_id'] = parameterToString(clientId);
  formParams[r'client_secret'] = parameterToString(clientSecret);
  if (username != null) {
    formParams[r'username'] = parameterToString(username);
  }
  if (password != null) {
    formParams[r'password'] = parameterToString(password);
  }
  if (refreshToken != null) {
    formParams[r'refresh_token'] = parameterToString(refreshToken);
  }
  if (totp != null) {
    formParams[r'totp'] = parameterToString(totp);
  }

  return apiClient.invokeAPI(
    path,
    'POST',
    queryParams,
    postBody,
    headerParams,
    formParams,
    contentTypes.isEmpty ? null : contentTypes.first,
  );
}