doAttemptLogin method

  1. @override
Future<AuthResponse> doAttemptLogin(
  1. BuildContext context, {
  2. dynamic credentials,
})
override

Implementation

@override
Future<AuthResponse> doAttemptLogin(BuildContext context, {credentials}) async {
  try {
    try {
      final String nonce = uuid();
      final shaOfNonce = crypto.sha256.convert(utf8.encode(nonce)).toString().replaceAll("-", '');

      if (infoX.isIOS || infoX.isMacOS) {
        final credential = await SignInWithApple.getAppleIDCredential(scopes: [
          AppleIDAuthorizationScopes.email,
          AppleIDAuthorizationScopes.fullName,
        ], nonce: shaOfNonce);

        final oauthCred = oAuthProvider.credential(
          idToken: credential.identityToken,
          accessToken: credential.authorizationCode,
          rawNonce: nonce,
        );

        /// Apple only allows one access with the token, so don't do anything with
        /// the token before sending it to Firebase
        return AuthResponse.success(oauthCred);
      } else {
        // ignore: unused_local_variable
        WebAuthenticationOptions? webOptions;
        try {
          final creds = ThirdPartyCreds.appleSignIn.credentials;
          webOptions = WebAuthenticationOptions(
            clientId: creds.clientId!,
            redirectUri: creds.redirectUrl!.toUri()!,
          );
        } catch (e) {
          print(e);
        }
        // var oAuthProvider = fb.OAuthProvider("apple.com")
        //   ..addScope('email')
        //   ..addScope('name')
        //   ..setCustomParameters({
        //     'client_id': webOptions!.clientId,
        //     'redirect_uri': webOptions.redirectUri.toString(),
        //     'scope': 'email name',
        //     // Request `code`, which is also what `ASAuthorizationAppleIDCredential.authorizationCode` contains.
        //     // So the same handling can be used for Apple and 3rd party platforms
        //     'response_type': 'code id_token',
        //     'response_mode': 'form_post',
        //     'nonce': shaOfNonce,
        //   });

        final cred = await fb.FirebaseAuth.instance.signInWithPopup(oAuthProvider);

        var ocred = cred.credential as fb.OAuthCredential;
        return AuthResponse.success(ocred);
        // final oauthCred = oAuthProvider.credential(
        //   idToken: cred.credential.identityToken,
        //   accessToken: credential.authorizationCode,
        //   rawNonce: nonce,
        // );
      }
    } catch (e, stack) {
      _log.severe("Error from server: $e", e, stack);
      return AuthResponse.error(e);
    }
  } catch (e, stack) {
    _log.severe("Error from server: $e", e, stack);
    return AuthResponse.error("There was an error logging you in");
  }
}