我已按照 this tutorial 在 Azure 移动应用程序上实现使用自定义提供程序的登录。后端工作完美,但是当我尝试登录到我的新自定义 Controller 时,我无法做到这一点。可以使用 Xamarin 和 java Android 来实现它,但无法使用 Objective C 或 Swift 来实现。
Microsoft Azure 移动 SDK only has two login implementations. 上的对象 MSClient
我已经尝试了这两种方法,但没有运气,回调总是返回一个空的客户端。 我还尝试存储由自己的 API 创建的 token ,将其用于登录调用,但再次失败。
这是我的 Swift 代码:
let client = MSClient(applicationURLString: "https://myApp.azurewebsites.net")
client.login(withProvider: "custom", urlScheme: "myApp", parameters: ["username": "pau", "password": "123456"], controller: self, animated: true) {user, error in
print("USER", user)
print("ERROR", error)
}
最佳答案
我们找到了一个解决方案,它非常简单,但是 msclient 文档不够清晰。您只需将您需要的任何内容(即:用户名、密码)作为 token 参数中的字典传递即可。
Client.msClient.login(withProvider: "auth", token: params, completion: {user, error in
print("USER", user)
print("ERROR", error)
print("USER ID", user?.userId)
print("TOKEN", user?.mobileServiceAuthenticationToken)
if let user: MSUser = user {
guard let username: String = user.userId else { return }
guard let token: String = user.mobileServiceAuthenticationToken else { return }
Client.username = username
Client.msClient.currentUser = user
completion(true)
}else {
completion(false)
}
})
关于swift - Microsoft Azure移动SDK自定义提供商登录IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47013333/