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 2882
刺人心
刺人心 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.

提交回复
热议问题