authenticate method

dynamic authenticate(
  1. dynamic callBack
)

Implementation

authenticate(callBack) async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  String token = prefs.getString(fieldToken) ?? "";
  if (!ignoreStoredToken && token.isNotEmpty) {
    callBack(oauth2.Client(oauth2.Credentials(token)));
    return;
  }
  _logMsg("Token not found, beginning oauth");
  authenticating = true;
  codeVerifier = _createCodeVerifier();
  prefs.setString("code_verifier", codeVerifier);

  oauth2.AuthorizationCodeGrant grant = oauth2.AuthorizationCodeGrant(
      clientId, Uri.parse("$host/$authPath"), Uri.parse("$host/$tokenPath"),
      httpClient: http.Client(), codeVerifier: codeVerifier);

  final authorizationUrl =
      grant.getAuthorizationUrl(redirectEndpoint, scopes: []);
  await _openAuthorizationServerLogin(authorizationUrl);
  if (!kIsWeb && (Platform.isAndroid || Platform.isIOS)) _runRedirectServer("0.0.0.0",7777,callBack);
}