Showing posts with label Facebook. Show all posts
Showing posts with label Facebook. Show all posts

Monday, 2 July 2012

Using Twitter As Your Flask Login Provider in 6 Lines

First off, I lied about the 6 lines, but it got you here and now you can see how simple it is yourself. There are actually 40 lines I think.

When I was building Flask Ahoy! I wanted to use Twitter as the login provider. I could spend a while boring you about why (as opposed to say Google, Facebook, OpenID or Roll-Your-Own), but I'l save that for another exciting post.

I have used the extremely handy Flask-OAuth to do all the legwork so you need to install that:

Next we need some html for users to click on to sign in and sign out. Try this simple block :

Next the real code begins. In your views module you need three views:

  • One to send you off to Twitter to get authorized (login)
  • One to get the callback from Twitter and store your authorization credentials (twitter_authorized)
  • One to log you out and tidy up (logout)

Finally we need a special little method which remembers your credentials:


Now for the sake of safety I'm going to point out a couple of things here:

  • This scenario uses flask sessions (encrypted cookies) to store your Twitter OAuth token.
  • When you logout, you are only destroying the twitter_user flag, you should probably destroy your credentials as well.


Good luck fellow travelers.

Monday, 6 June 2011

Use Twitter and Facebook with Ubuntu 11.04 (Natty) or Mint 11

Ubuntu's preferred Internet Messenger is not Pidgin which with a little love can happily act as your Twitter and Facebook  messenger/client.

You want to install the pidgin-microblog package which I think used to be called purple-pidgin:

sudo apt-get install pidgin-microblog

Strictly, Facebook doesn't need this, but it makes the experience nicer.

Now you want to start up Pidgin and do "Accounts/Manage Accounts" (or CTRL+a).

Add Twitter

"Add" (or ALT+a) then the protocol should be "TwitterIM"


and then "add and that's it"

Add Facebook

Facebook is almost the same, EXCEPT that you may or not actually know your Facebook username if you, like me have always used your email address and password.

You can find it at Facebook, in the top right hand corner there's drop down called "Account" then "Account Settings/Settings/Username" which will show you what it is.

Then back in Pidgin do "Accounts/Manage Accounts" (or CTRL+a) "Add" (or ALT+a) then the protocol should be "Facebook (XMPP)" and enter your details:



Note the Resource = Pidgin entry.

Have fun and please comment on any problems you come across.