Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Sign Out of Apple After Being Authenticated

My app has a "Sign in with the Apple" account feature. I am wondering if there is sign out feature from the Apple account.

I tried the below but doesn't get success

    let request = ASAuthorizationAppleIDProvider().createRequest()

    request.requestedOperation = .operationLogout

    let authorizationController = ASAuthorizationController(authorizationRequests: [request])

    authorizationController.performRequests()
like image 801
Dipendra Dubey Avatar asked Nov 13 '19 11:11

Dipendra Dubey


People also ask

How do I sign out of Apple ID on Xcode?

Open Keychain Access, go to the Passwords category and remove the passwords associated with Xcode. Their name contains apple.com (example: daw2.apple.com).

Can you have two Apple IDs?

You can log in and set up multiple Apple IDs on an iOS device from the Settings app, and use them for different purposes like contacts, email, notes, bookmarks, etc.


1 Answers

Apple only allows currently for the user to perform a signout (iOS/watchOS/tvOS) or shown as a revoke of permissions to us. They recommend you get the state of the credentials before use to check for revoke and if that has occurred to delete any local information (Remove the user identifier where ever you have it stored) (And possibly change UI if needed; For example like showing login view).

        let appleIDProvider = ASAuthorizationAppleIDProvider()
    appleIDProvider.getCredentialState(forUserID: KeychainItem.currentUserIdentifier) { (credentialState, error) in
        switch credentialState {
        case .authorized:
            // The Apple ID credential is valid.
            break
        case .revoked:
            // The Apple ID credential is revoked.
            break
        case .notFound:
            // No credential was found, so show the sign-in UI.
            break
        default:
            break
        }
    }

You could provide a prompt to the user on signout guiding them to revoke in their device's settings as well and listen for the change notification.

like image 158
SierraMike Avatar answered Sep 28 '22 02:09

SierraMike