webAuth method

  1. @override
Future webAuth(
  1. Uri url, {
  2. String? callbackUrlScheme,
})
override

Implementation

@override
Future webAuth(Uri url, {String? callbackUrlScheme}) {
  return FlutterWebAuth2.authenticate(
    url: url.toString(),
    callbackUrlScheme: callbackUrlScheme != null && Platform.isWindows
        ? callbackUrlScheme
        : "appwrite-callback-" + config['project']!,
    preferEphemeral: true,
  ).then((value) async {
    Uri url = Uri.parse(value);
    final key = url.queryParameters['key'];
    final secret = url.queryParameters['secret'];
    if (key == null || secret == null) {
      throw AppwriteException(
          "Invalid OAuth2 Response. Key and Secret not available.", 500);
    }
    Cookie cookie = Cookie(key, secret);
    cookie.domain = Uri.parse(_endPoint).host;
    cookie.httpOnly = true;
    cookie.path = '/';
    List<Cookie> cookies = [cookie];
    await init();
    _cookieJar.saveFromResponse(Uri.parse(_endPoint), cookies);
  });
}