When I use the apple to log in, the selection box will pop up. I choose to use the password to continue and the prompt is not complete

后端 未结 7 2885
刺人心
刺人心 2021-02-20 05:40

iOS13 (beta) Apple Login error

@available(iOS 13.0, *)
    func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error)         


        
相关标签:
7条回答
  • 2021-02-20 06:11

    In my case, launching ASAuthorizationController including a request for ASAuthorizationPasswordProvider was causing the error.

    Failed to complete operation. (com.apple.AuthenticationServices.AuthorizationError error 1000.)


    From the ASAuthorizationError.Code documentation; 1000 is for unknown

    ASAuthorizationError.Code.unknown

    The authorization attempt failed for an unknown reason.

    Declaration

    case unknown = 1000
    

    Ref: https://developer.apple.com/documentation/authenticationservices/asauthorizationerror/code/unknown

    Now that's not particularly helpful but did give me a clue to check my ASAuthorizationController setup which I was trying to launch with 2 requests from ASAuthorizationAppleIDProvider & ASAuthorizationPasswordProvider, like so:

    func loginWithAppleButtonPressed() {
        let appleSignInRequest = ASAuthorizationAppleIDProvider().createRequest()
        appleSignInRequest.requestedScopes = [.fullName, .email]
    
        let anySignInRequest = ASAuthorizationPasswordProvider().createRequest()
    
        let controller = ASAuthorizationController(authorizationRequests: [appleSignInRequest, 
                                                                           anySignInRequest])
        controller.delegate = self
        controller.presentationContextProvider = self
    
        controller.performRequests()
    }
    

    I tried this on a simulator that had an Apple ID with 2FA enabled and also on a device with another Apple ID without 2FA, and both times it would just go to authorizationController(controller:didCompleteWithError error:) and that's it.


    Solution:

    So to keep it simple, I launched ASAuthorizationController with only ASAuthorizationAppleIDProvider like so:

    func loginWithAppleButtonPressed() {
        let appleSignInRequest = ASAuthorizationAppleIDProvider().createRequest()
        appleSignInRequest.requestedScopes = [.fullName, .email]
    
        let controller = ASAuthorizationController(authorizationRequests: [appleSignInRequest])
        controller.delegate = self
        controller.presentationContextProvider = self
    
        controller.performRequests()
    }
    

    And voilà! This time things worked as expected:

    1. When using an Apple ID with 2FA
      • popped up with the login request
    2. When using an Apple ID without 2FA
      • popped up an error telling me to enable 2FA
      • called authorizationController(controller:didCompleteWithError error:) with error 1000

    So seems that in my case ASAuthorizationPasswordProvider was the culprit but since ASAuthorizationError.Code.unknown is a generic error case, this solution may not work for you.

    Also, In my case I need only ASAuthorizationAppleIDProvider for Apple ID sign in so dropped the support for ASAuthorizationPasswordProvider.

    0 讨论(0)
  • 2021-02-20 06:19

    I resolved this by holding my finger down on finger print scanner til completion. I'm not an iphone user so I'm not used to the finger print scanner. If you pull your finger off too soon you get this error.

    0 讨论(0)
  • 2021-02-20 06:20

    I've resolved it by adding sign in with apple as key in entitlements plist .

    0 讨论(0)
  • 2021-02-20 06:21

    From Apple's example,

    performExistingAccountSetupFlows, only call this method once on viewDidAppear. If user info exists already then Apple will show it to login. If not then it will throw error.

    handleAuthorizationAppleIDButtonPress, whenever user taps on Sign in with Apple button, note that if an account already had existed it would have shown it to the user already. I believe its still in progress and not all use cases are covered, for example if user sees the login info initially from ViewDidAppear call and cancels it then user have to create a new account when tapping on this method since its missing ASAuthorizationPasswordProvider request. If user had some login info then in that case this call (with ASAuthorizationPasswordProvider) will succeed but if no data is available then user will not see any action on tapping this button since it will throw error.

    I am still figuring this out, if I have anything more to add then I will update the answer. So, for now we can only have this one use case to use this Sign in with Apple option.

    Update: Once I created a new account, I was offered by this same flow to login with the already existing account. So, I can say that there is no need to include call to ASAuthorizationPasswordProvider request in handleAuthorizationAppleIDButtonPress method. I am doing all the testing on device.

    You can always go to Settings -> AppleId -> Password & Security -> Apple ID Logins to check and delete account if you need to test various scenarios.

    Update 2: Everything seems to work fine in other scenarios too if you already have a saved password or App Id account created, so even if I pass ASAuthorizationPasswordProvider in the handleAuthorizationAppleIDButtonPress call, it is working fine. I would suggest to not pass ASAuthorizationPasswordProvider in the next call and keep the flow as described above, this way if no saved password is present or Apple Id created then it will provide option to the user to create a new id, if there is already an id that exists then it will show that id.

     override func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
            performExistingAccountSetupFlows()
        }
    
        func performExistingAccountSetupFlows() {
            // Prepare requests for both Apple ID and password providers.
            let requests = [ASAuthorizationAppleIDProvider().createRequest(),
                            ASAuthorizationPasswordProvider().createRequest()]
    
            // Create an authorization controller with the given requests.
            let authorizationController = ASAuthorizationController(authorizationRequests: requests)
            authorizationController.delegate = self
            authorizationController.presentationContextProvider = self
            authorizationController.performRequests()
        }
    
        @objc
        func handleAuthorizationAppleIDButtonPress() {
            let appleIDProvider = ASAuthorizationAppleIDProvider()
            let request = appleIDProvider.createRequest()
            request.requestedScopes = [.fullName, .email]
    
            let authorizationController = ASAuthorizationController(authorizationRequests: [request])
            authorizationController.delegate = self
            authorizationController.presentationContextProvider = self
            authorizationController.performRequests()
        }
    
    0 讨论(0)
  • 2021-02-20 06:23

    Simply Add + "Sign In with Apple" from Capability.

    0 讨论(0)
  • 2021-02-20 06:29

    I've encountered the same issue yesterday and I've managed to fix it following these steps:

    1. Go to https://appleid.apple.com/account/manage, under the Devices section you should find devices on which you are signed in with your Apple ID,
    2. Find device/simulator on which Apple SSO is not working, click on it and click remove from the account,
    3. Go back to your device/simulator settings, it will ask you to authenticate again. When you successfully authenticate, Apple SSO should work again!

    I'm not sure what caused this issue, probably some issue between the simulator and Apple ID.

    0 讨论(0)
提交回复
热议问题