我正在尝试通过 Firebase 对 Digits 用户进行身份验证。我不止两次听说您可以通过 twitter 端点对 Digits 用户进行身份验证。所以我现在正在尝试,但我几乎被卡住了。我正在尝试将 session?.authToken 发送到 Firebase,以便我可以创建用户。Digits 看起来真的很酷,所以我很确定我想坚持下去。如果这完全不可能,我也非常感谢被指出能够使用数字的 BaaS 的方向。在此先感谢,这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let authButton = DGTAuthenticateButton(authenticationCompletion: { (session: DGTSession?, error: NSError?) in
if (session != nil) {
// TODO: associate the session userID with your user model
let message = "Phone number: \(session!.phoneNumber)"
let alertController = UIAlertController(title: "You are logged in!", message: message, preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: .None))
self.presentViewController(alertController, animated: true, completion: .None)
DataService.FireBase.Surfer.authWithOAuthProvider("twitter", token: session!.authToken, withCompletionBlock: { error, newAuthData in
if error != nil {
print(error)
} else {
print(newAuthData)
}
})
} else {
NSLog("Authentication error: %@", error!.localizedDescription)
}
})
authButton.center = self.view.center
self.view.addSubview(authButton)
let button = UIButton(type: UIButtonType.System) as UIButton
button.frame = CGRectMake(100, 100, 100, 50)
button.backgroundColor = UIColor.greenColor()
button.setTitle("Test Button", forState: UIControlState.Normal)
button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
}
func buttonAction(sender:UIButton!)
{
print("Button tapped")
print(authTkn)
Digits.sharedInstance().logOut()
}
这是数据服务:
class DataService{
static let FireBase = DataService()
private var _REF_BASE = Firebase(url: "https://testingtoday.firebaseio.com")
var Surfer: Firebase {
return _REF_BASE
}
}