I am trying to authenticate a Digits user via Firebase. I have heard on more than two occasions that you can auth Digits users through the twitter end-points. So I'm trying it now but I'm pretty much stuck. I am trying to send the session?.authToken to Firebase so that I can create a user. Digits looks really cool and so I'm pretty sure that I want to stick with it. If this is totally impossible I would also really appreciate being pointed in the direction of a BaaS that would be able to work with digits. Thanks in advance and here is my code:
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()
}
and here is the DataService:
class DataService{
static let FireBase = DataService()
private var _REF_BASE = Firebase(url: "https://testingtoday.firebaseio.com")
var Surfer: Firebase {
return _REF_BASE
}
}