首页 > 解决方案 > 使用 Swift 将 LinkedIn 身份验证集成到 iOS 中的 Firebase 身份验证

问题描述

我在这里很新,但我已经在 swift (ver. 4) 中开发了大约 3 个月。因此,我在使用 Web 视图实现 LinkedIn 身份验证时遇到了这个问题,因为我不想在需要 LinkedIn 应用程序的情况下使用身份验证——UX 的东西。

我使用以下指南来完成此操作,但我只能获得访问令牌,但存在卡在登录过程中的错误。当我调试应用程序时,我能够获取访问令牌,但 Web 视图的视图控制器不会关闭。

这些是我使用的指南:

问题:

  1. 获取访问令牌后无法关闭视图控制器。
  2. 使用 Firebase 自定义身份验证的访问令牌在哪里获取所需的“自定义令牌”。

问题 #1的代码片段

    // Initialize a NSURLSession object.
    let session = URLSession(configuration: URLSessionConfiguration.default)

    // Make the request.
    let task: URLSessionDataTask = session.dataTask(with: request) { (data, response, error) -> Void in

        // Get the HTTP status code of the request.
        let statusCode = (response as! HTTPURLResponse).statusCode

        if statusCode == 200 {
            // Convert the received JSON data into a dictionary.
            do {
                let dataDictionary = try JSONSerialization.jsonObject(with: data!, options: []) as! [String : AnyObject]

                let accessToken = dataDictionary["access_token"] as! String

                UserDefaults.standard.set(accessToken, forKey: "LIAccessToken")
                UserDefaults.standard.synchronize()

//              Custom Firebase Auth
//              Auth.auth().signIn(withCustomToken: UserDefaults.standard.string(forKey: "LIAccessToken")!) { (user, error) in
//                  if let error = error {
//                        print(error)
//                        return
//                  }
//
//              }

                DispatchQueue.main.async {
                    self.dismiss(animated: true, completion: nil)
                }
            } catch {
                print("Could not convert JSON data into a dictionary.")
            }
        }
    }

    task.resume()

提前感谢任何帮助!我希望能够帮助那些有同样问题的人。

标签: iosswiftfirebase

解决方案


推荐阅读