loginWithOidc static method

Future<LoginSession> loginWithOidc({
  1. required OidcProviderType type,
  2. required String authorizationUrl,
})

Implementation

static Future<LoginSession> loginWithOidc({
  required OidcProviderType type,
  required String authorizationUrl,
}) async {
  await HeraExtenstion.redirect(Uri.parse(authorizationUrl));
  final Completer<Uri> completer = Completer<Uri>();
  _sub = linkStream.listen((String? uri) async {
    if (uri.toString().startsWith(_redirectUrl)) {
      if (Platform.isIOS || Platform.isAndroid || Platform.isFuchsia) {
        await closeInAppWebView();
      }
      completer.complete(Uri.parse(uri!));
    }
  });
  Uri _responseUrl = await completer.future;
  _sub?.cancel();
  HeraRequest req = HeraRequest()..namespace = _namespace;
  req.oidcProvider = OidcProvider()..type = type;
  //req.redirectAddr = _oidcRedirectAddress;

  String? accessToken = _responseUrl.queryParameters["access_token"];
  String? refreshToken = _responseUrl.queryParameters["access_token"];
  String? userId = _responseUrl.queryParameters["user_id"];
  if ((accessToken ?? "") == "" || (refreshToken ?? "") == "") {
    throw Exception(
        "user id, access or refresh token is null. Contact info@nuntio.io");
  }
  if (userId == "") {
    throw Exception("user is null. Contact info@nuntio.io");
  }
  var response = await _heraClient.get(HeraRequest(
    accessToken: accessToken,
  ));
  _setCurrentUser(response.user);
  _setAccessToken(accessToken!);
  _setRefreshToken(refreshToken!);
  return LoginSession()..loginStatus = LoginStatus.AUTHENTICATED;
}