无法为iOS Swift4.2使用MSAL进行身份验证

时间:2020-07-20 13:54:40

标签: ios swift msal swift4.2

我无法执行MSAL SDK。我遇到了下面提到的问题...我经历了很多StackOverflow问题,但仍然无法解决此问题。

问题:

qwerty[66144:4049892] -canOpenURL: failed for URL: "msauthv2://broker" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
qwerty[66144:4052892] Failed to query AuthBrokerAgent Task <49DC4AA3-FAC7-4268-94DA-41FE68FD584F>.<1>
qwerty[66144:4052892] CredStore - performQuery - Error copying matching creds.  Error=-25300, query={
    class = inet;
    "m_Limit" = "m_LimitAll";
    ptcl = htsx;
    "r_Attributes" = 1;
    srvr = "intpxy1.ind.mobi";
    sync = syna;
}
qwerty[66144:4052492] Failed to get applicable proxy auth Task <49DC4AA3-FAC7-4268-94DA-41FE68FD584F>.<1>
qwerty[66144:4050495] Task <49DC4AA3-FAC7-4268-94DA-41FE68FD584F>.<1> HTTP load failed (error code: 311 [4:-2097])
qwerty[66144:4052491] Task <49DC4AA3-FAC7-4268-94DA-41FE68FD584F>.<1> finished with error - code: 311
App error: Error Domain=kCFErrorDomainCFNetwork Code=311 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2097, _kCFStreamErrorDomainKey=4}
qwerty[66144:4052495] Received XPC error Connection interrupted for message type 3 kCFNetworkAgentXPCMessageTypePACQuery
qwerty[66144:4052495] Received XPC error Connection invalid for message type 3 kCFNetworkAgentXPCMessageTypePACQuery

我的系统配置:

  • Mac OS:macOS High Sierra
  • XCode Ver:版本10.1(10B61)

请帮助我。

1 个答案:

答案 0 :(得分:0)

请检查以下所有内容是否到位: kClientID,kAuthority,LSApplicationQueriesSchemes。另外,请确保您拥有有效的Microsoft帐户。我最近集成了Microsoft登录,如下所示。

func initMSAL() throws {
        guard let authorityURL = URL(string: kAuthority) else {
            return
        }
        let authority = try MSALAADAuthority(url: authorityURL)
        let msalConfiguration = MSALPublicClientApplicationConfig(clientId:kClientID, redirectUri: nil, authority: authority)
        self.applicationContext = try MSALPublicClientApplication(configuration: msalConfiguration)
    }


    func loginUser(completion:@escaping((Bool) -> Void)) {
        guard let applicationContext = self.applicationContext else { return }
        let parameters = MSALInteractiveTokenParameters.init(scopes: kScopes, webviewParameters: MSALWebviewParameters(parentViewController: (UIApplication.shared.windows.last?.rootViewController)!))
        parameters.promptType = .selectAccount
        applicationContext.acquireToken(with: parameters) { (result, error) in
            if let error = error {
                print("Could not acquire token: \(error)")
                return
            }

            guard let result = result else {
                print("Could not acquire token: No result returned")
                return
            }
            print("Access Token is:", result.accessToken)
            
            completion(true)
        }
    }