login static method

Future<bool> login({
  1. bool tokenLoop = true,
  2. String? redirectUrl,
  3. String? clientId,
  4. String? realm,
  5. String? authServerUrl,
})

Will open up a browser showing the authentication provider and attempt to get a token. Returns true on a successful token. Calls Session.onToken on success so you can get your token from Session.token. Setting tokenLoop to true will automatically make it call Session.startTokenLoop on successful login

Implementation

static Future<bool> login(
    {bool tokenLoop = true,
    String? redirectUrl,
    String? clientId,
    String? realm,
    String? authServerUrl}) async {
  _logger.debug("Trying to log in!");
  if (!_checkFields(redirectUrl, clientId, realm, authServerUrl)) {
    return false;
  }

  _logger.debug("Discovery URL is: $discoveryUrl");

  AuthorizationTokenResponse? result =
      await _appAuth.authorizeAndExchangeCode(AuthorizationTokenRequest(
          _clientId!, _redirectUrl!,
          discoveryUrl: discoveryUrl, scopes: _scopes));

  if (result == null) {
    _logger.warning("Auth Token Request returned null!");
    return false;
  }

  bool success = Session.onToken(result);

  if (success) {
    Session.startTokenLoop();
  }
  return success;
}