Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do with twitter oauth token once retrieved?

I'm writing a web app that will use twitter as its primary log on method. I've written code which gets the oauth token back from Twitter. My plan is now to

  1. Find the entry in my Users table for the twitter username retrieved using the token, or create the entry if necessary
  2. Update the Users.TwitterOAuthToken column with the new OAuth token
  3. Create a permanent cookie with a random guid on the site and insert a record into my UserCookies table matching Cookie to User
  4. when a request comes in I will look for the browser cookie id in the UserCookies table, then use that to figure out the user, and make twitter requests on their behalf
  5. Write the oauth token into some pages as a js variable so that javascript can make requests on behalf of the user
  6. If the user clears his/her cookies the user will have to log in again to twitter

Is this the correct process? Have I created any massive security holes?

like image 315
mcintyre321 Avatar asked May 12 '10 16:05

mcintyre321


People also ask

How do I know if my Twitter access token has expired?

Access tokens are not explicitly expired. An access token will be invalidated if a user explicitly revokes an application in the their Twitter account settings, or if Twitter suspends an application. If an application is suspended, there will be a note in the Twitter app dashboard stating that it has been suspended.

What is OAuth used for on Twitter?

An open protocol to allow secure authorization in a simple and standard method from web, mobile and desktop applications. OAuth is the most common authorization framework today, and it is used on most common web applications and services, like GitHub, Google, Facebook, and, of course, Twitter.

How long do Twitter tokens last?

Tokens from Twitter do not have an expiration time, but they can become invalid after the user has rejected your application. Also, the Twitter crew can suspend your application if you are exceeding limits or performing other actions that violate the API Terms.

Can the access token be used over HTTPS connection?

The application should ensure the storage of the access token is not accessible to other applications on the same device. The access token can only be used over an https connection, since passing it over a non-encrypted channel would make it trivial for third parties to intercept.


1 Answers

Sounds good.

However, I suggest not using the Twitter User Name as the primary index for the User table. As Twitter user names can be changed. I learned this the hard way.

You should be fine using the Twitter User ID (big int) as the primary index as it doesn't change if the user changes their user name.

As for the token its self, you are a-okay with storing it for future use. In fact, you are encouraged to do so.

like image 115
Jayrox Avatar answered Sep 18 '22 13:09

Jayrox