getAccessToken method

dynamic getAccessToken(
  1. String username,
  2. String password
)

Implementation

getAccessToken(String username, String password) async {
  final authorizationEndpoint =
  Uri.parse(GlobalVariables.urlEndPoint! + "/rest/v2/oauth/token?");

  try {
    _client = await oauth2.resourceOwnerPasswordGrant(
        authorizationEndpoint, username, password,
        identifier: GlobalVariables.identifier, secret: GlobalVariables.secret);
  } on SocketException catch (e) {
    dev.log('Socket Exception', name: libName, error: e);
    return GlobalVariables.connectionTimeCode;
  } on oauth2.AuthorizationException catch (e) {
    dev.log('Auth Exception', name: libName, error: e);
    return GlobalVariables.accessErrorCode;
  } on FormatException catch (e) {
    dev.log('Format Exception', name: libName, error: e);
    return e.message;
  } on HandshakeException catch (e) {
    dev.log('Socket Exception', name: libName, error: e);
    return e.toString();
  }
  GlobalVariables.token = _client!.credentials.accessToken;

  var box = await Hive.openBox('credentials');
  box.put('json', _client!.credentials.toJson());
  return _client;
}