linkWithOAuth method

  1. @override
Future<OAuthCredential> linkWithOAuth(
  1. String provider,
  2. List<String> scopes, [
  3. Map<String, String>? customOAuthParameters
])
override

Starts a OAuth sign-in flow for provider using Firebase. The instance of FirebaseAuth will be from the default Firebase App Unless withApp is used to build an instance. The credentials will be added to the existing Firebase User An error will be throw if there's no Firebase User It will return authentication result OAuthCredential. If supported by Firebase, this will contains the provider access token as accessToken.

Implementation

@override
Future<OAuthCredential> linkWithOAuth(String provider, List<String> scopes,
    [Map<String, String>? customOAuthParameters]) async {
  final oAuthProvider = web.OAuthProvider(provider);
  scopes.forEach((scope) => oAuthProvider.addScope(scope));
  if (customOAuthParameters != null) {
    oAuthProvider.setCustomParameters(customOAuthParameters);
  }
  if (FirebaseAuth.instanceFor(app: _app()).currentUser == null) {
    return Future.error(StateError(
        "currentUser is nil. Make sure a user exists when linkWithOAuth is used"));
  }
  final result = await web
      .app(_app().name)
      .auth()
      .currentUser
      ?.linkWithPopup(oAuthProvider);

  return OAuthCredential(
    signInMethod: "oauth",
    providerId: result?.credential.providerId ?? "",
    accessToken: result?.credential.accessToken,
    idToken: result?.credential.idToken,
    secret: result?.credential.secret,
  );
}