loginOrRefresh method
Login or refresh token
Login with username and password, or refreshes the token when refresh token is supplied
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<AuthenticationResponse?> loginOrRefresh(
String grantType,
String clientId,
String clientSecret, {
String? username,
String? password,
String? refreshToken,
String? totp,
}) async {
final response = await loginOrRefreshWithHttpInfo(
grantType,
clientId,
clientSecret,
username: username,
password: password,
refreshToken: refreshToken,
totp: totp,
);
LogbotLogger().simple("loginOrRefresh(): RESPONSE BODY: ${response.body}");
LogbotLogger().simple(
"loginOrRefresh(): RESPONSE REQUEST: ${response.request} - ${response.headers} - ${response.request}");
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),
'AuthenticationResponse',
) as AuthenticationResponse;
}
return null;
}