菜鸟教程小白 发表于 2022-12-11 17:18:40

ios - 在 Swift 中找不到使用 Google 客户端库的用户的 serverAuthCode


                                            <p><p>所以我遇到的问题是我正在尝试使用带有 Google API 客户端库的客户端身份验证对 Azure 进行身份验证。我可以获得刷新、访问和 IDtoken ,但 serverAuthCode 是 <code>nil</code>。我需要 serverAuthCode 来创建调用 Azure 身份验证端点的 HTTP 请求。适用于 iOS 的 Azure SDK 不支持 Google 的客户端身份验证(我曾与 Microsoft 的多名工程师交谈过,他们都建议不要使用他们的 SDK 进行身份验证,因为他们不支持它)。我不知道该怎么做,除了试着绕着 AWS 转。有什么帮助吗?</p>

<p>另外,这是一段代码</p>

<pre><code>func viewController(vc : UIViewController, finishedWithAuth authResult : GTMOAuth2Authentication, error : NSError?) {

    let azureGoogleServerAuthToken = authResult.userData.serverAuthCode

    let azureGoogleIdToken = authResult.parameters[&#34;id_token&#34;] as! String

    let request = NSMutableURLRequest(URL: NSURL(string: &#34;https://retip-ios.azurewebsites.net/.auth/login/google&#34;)!)
    request.HTTPMethod = &#34;POST&#34;
    let postString = &#34;authorization_code=\(azureGoogleServerAuthToken)&amp;id_token=\(azureGoogleIdToken)&#34;
    request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
    let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
      guard error == nil &amp;&amp; data != nil else {                                                          // check for fundamental networking error
            print(&#34;error=\(error)&#34;)
            return
      }

      if let httpStatus = response as? NSHTTPURLResponse where httpStatus.statusCode != 200 {         // check for http errors
            print(&#34;statusCode should be 200, but is \(httpStatus.statusCode)&#34;)
            print(&#34;response = \(response)&#34;)
      }

      let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
      print(&#34;responseString = \(responseString)&#34;)
    }
    task.resume()
</code></pre>

<p>它失败了,但有一个异常说它每次都找到 nil。我已将其隔离出来以验证这是导致异常的原因。</p>

<p>提前致谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在直接与 Azure 支持人员交谈并与他们一起工作了一个多星期以找到解决方案后,似乎他们的文档在此问题上故意含糊其辞,因为他们不支持通过 Google 进行客户端身份验证。任何解决方案都需要自定义构建,这意味着通过 Azure SDK 无法实现。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在 Swift 中找不到使用 Google 客户端库的用户的 serverAuthCode,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39048787/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39048787/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在 Swift 中找不到使用 Google 客户端库的用户的 serverAuthCode