Home > database >  How do I do sign in with apple ID with json and revoke token when user wants to permanently deactiva
How do I do sign in with apple ID with json and revoke token when user wants to permanently deactiva

Time:08-18

So far I have managed to get these

String generateNonce([int length = 32]) {
    final charset =
        '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
    final random = Math.Random.secure();
    return List.generate(length, (_) => charset[random.nextInt(charset.length)])
        .join();
  }

String sha256ofString(String input) {
  final bytes = utf8.encode(input);
  final digest = sha256.convert(bytes);
  return digest.toString();
}

And I have used sign-in-with-apple for signing in .


Future<UserCredential> signInWithApple() async {
  try {
    final rawNonce = generateNonce();
    final nonce = sha256ofString(rawNonce);

    // Request credential for the currently signed in Apple account.
    final appleCredential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
      nonce: nonce,
    );

    // Create an `OAuthCredential` from the credential returned by Apple.
    final oauthCredential = OAuthProvider("apple.com").credential(
      idToken: appleCredential.identityToken,
      rawNonce: rawNonce,
    );

    String authCodeString =
        getAppleAuthorizationCode(appleCredential.authorizationCode);
    log(authCodeString);

    return await FirebaseAuth.instance.signInWithCredential(oauthCredential);
  } on FirebaseAuthException catch (e) {
    debugPrint(e.message);
    debugPrint("CODE ${e.code}");
    throw e;
  }
}

As per recent requirement of apple, we need to provide option to permanently revoke app-permission and information for user upon request. How do we do this? Please help me understanding it as much as possible. Thank you ! :)

CodePudding user response:

This signin with apple is only an authentication method. Once a user authenticates using this method you will get a unique email or id of that user. Then with this email you will be saving the user in your db or firebase. Apple wants us to create a mechanism where the users can permanently delete their account. In this case you should be deleting this database entry permanently and logging out the user. They also approve manual deletion process where a person will manually delete the account from the db but we should provide an option for the user to initiate this processs from the app. And it should be clearly visible saying delete account maybe.

  • Related