Search code examples
iosswiftios13apple-sign-in

Sign out after apple sign in


I just integrated new apple sign in into my app. The first time when I tried sign up I received fullName, email and other credentials in didCompleteWithAuthorization method, but on every next attempt fullName, email and other user data is nil. I think that's because the jwt token is already generated. I tried to research hot to log out but couldn't find any solution. If someone had the same issue please help me. For testing, I need getting credentials multiple times. So I need to logout somehow.

That's how I request:

    let provider = ASAuthorizationAppleIDProvider()
    let request = provider.createRequest()
    request.requestedScopes = [.fullName, .email]
    let controller = ASAuthorizationController(authorizationRequests: [request])
    controller.delegate = self
    controller.presentationContextProvider = self
    controller.performRequests()

Solution

  • This behaves correctly

    User info is only sent in the ASAuthorizationAppleIDCredential upon initial user sign-up. Subsequent logins to your app using Sign In with Apple with the same account do not share any useful info and will only return a user identifier in the ASAuthorizationAppleIDCredential. It is recommended that you securely cache the initial ASAuthorizationAppleIDCredential containing the user info until you can validate that an account has successfully been created on your server. So next time when a user signs in you have to fetch email and other details from your server using the identifier as apple always returns the same identifier even when you delete the application and install it back.