ios - 使用 Swift 将 LinkedIn 身份验证集成到 iOS 中的 Firebase 身份验证
问题描述
我在这里很新,但我已经在 swift (ver. 4) 中开发了大约 3 个月。因此,我在使用 Web 视图实现 LinkedIn 身份验证时遇到了这个问题,因为我不想在需要 LinkedIn 应用程序的情况下使用身份验证——UX 的东西。
我使用以下指南来完成此操作,但我只能获得访问令牌,但存在卡在登录过程中的错误。当我调试应用程序时,我能够获取访问令牌,但 Web 视图的视图控制器不会关闭。
这些是我使用的指南:
- 领英身份验证:https ://www.appcoda.com/linkedin-sign-in/
- 自定义 Firebase 身份验证:https ://firebase.google.com/docs/auth/ios/custom-auth
问题:
- 获取访问令牌后无法关闭视图控制器。
- 使用 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()
提前感谢任何帮助!我希望能够帮助那些有同样问题的人。
解决方案
推荐阅读
- uwp - 在 Prism.Windows 7.1.0 中创建外壳的替代方法?
- amazon-cognito - Cognito - 当设备时区为 EDT 且当前时间设置为 IST 时,用户无法登录
- angular - 将文档引用过滤为字段
- graphql - 查询 graphiql 导致 Apollo 错误转发不是函数
- assembly - 通过CTF学习逆向
- c# - 如何在 Asp.net MVC C# 中从会话而不是数据库中插入和获取数据
- reporting-services - 如何将页脚放在矩形内
- javascript - 使用 video.js 需要 CORS
- google-apps-script - 输入后立即将 Google 表单答案写入工作表
- extentreports - 范围报告:无法为多个套件生成报告。