PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, September 3, 2022

[FIXED] How do I do sign in with apple ID with json and revoke token when user wants to permanently deactivate account in flutter/dart?

 September 03, 2022     apple-sign-in, authentication, dart, flutter, ios     No comments   

Issue

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 ! :)


Solution

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.



Answered By - Kaushik Chandru
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing