Login A User in iPhone with Twitter and Save Authenticated User to Remote Django Application
I have a vague idea of how to do th开发者_如何学编程is.
My app is consuming an API written in Django, but my client required me to do authentication only with Twitter. The problem is, after I log them into the iPhone app via Twitter, how will I then be able to work with Django's User model?
By the way, I am using django-tastypie with Django and ASIHTTPRequest with iOS.
Thanks!
Ygam,
I am using Facebook Connect/Graph within my app (and on our site) and have an API wrapped around my Django site using Piston. I am actually considering to go to TastyPie, but no time to refactor at the moment.
I faced a similar problem when we introduced FB, so I decided to use an API token for all API calls and issue that token at successful login, no matter what authentication mechanism was going to be used (django user/pw, FB, Twitter etc.)
Currently users can login into the app with either username/pw or FB. A login consists of a 'GET' over HTTPS that returns a profile json ( I could have first returned an API token and have app make another call for the profile json, but when dealing with mobile devices and slow networks you want to reduce network calls).
The token is stored locally and will work until the server decides to revoke it (expire, manually by user on web site etc.)
So now my 'GET /profile' simply supports different url parameters based on authentication mechanism used like username/passsword for Django, fbtoken for Facebook, twtoken etc. and on server side I use Django to validate external tokens with the 3rd party api. This is also used to get FB profile data like email address and store that in the Django model.
I haven't looked at the Twitter integration in iOS5, but as long as you can get an auth token you could do something similar.
精彩评论