Dec 10 2010
Flickr authentication process (war stories)
I’ve recently been trying to add publishing support to ComicBake, so that comics can easily be uploaded to remote servers. I started looking at Flickr support because that’s where I would put my comics if I had any. Also it means I would be able to upload work-in-progress shots much quicker.
I spent some time reading over Flickr’s extensive but not very clear API documents. I registered my app with Flickr and received in return a “key” and a “secret”, which are used for signing in. Now I’m not quite sure how the key/secret pair work with open source software. There’s no way I can get round the fact that these two items will be stored in the source. I can obfuscate them in some way, but inevitably the obfuscation mechanism will be documented in the code, because I have to be able to undo it!
On top of that, if someone wants to get a Flickr key they can get one for free in two minutes like I did. The only real reason to secure the key is to prevent other people from writing apps with that key, thus masquerading as your app, and abusing the service. In that case the key would be revoked which would be a pain requiring a new key and new binaries to be distributed. But the chances of someone going to that effort are practically zero, I think.
Anyway, once you’ve got the key and secret to identify your app you need to authenticate yourself in order to change things on Flickr. The authentication process can be boiled down to three discrete steps:
- Get a frob. Now I have no idea what a “frob” is, but it appears to be a nonce, which in security terms is a one-use random number. You log in with the key and secret and say, “gies a frob!” and you get a random number in return. This random number is stored by Flickr for an hour and then forgotten, so you have an hour to complete the next step.
With your new frob and your authentication details you construct a web address which is unique to this instance, since the frob is (probably) unique and so is the key/secret. The user then has to load the page up and authorise your app.
http://api.flickr.com/services/auth/?api_key=1234&frob=6789&perms=write&api_sig=162738
Once that’s done you can request a token from the Flickr server. The token is only handed out once per login, so if it’s lost you need to start again at step one. The token can be saved to disk and re-used as many times as needed by this application, but the user may revoke access at any time from the Flickr website, so be ready to discard saved tokens.
The specification requires that you let users “log out” too. Since there is no way to revoke your own permissions remotely you can simply delete any local tokens you have, which is as good.
I managed all of the above fairly easily with the Haskell Flickr bindings put together by Sigbjorn Finne. The uploading stage is where I stalled and it seems to be a problem in the library since the included example programs give the same error message I’m getting:
toRequest: POST request contains 1 files; unable to represent as query string Defaulting to multiform/form-data instead Flickr error: Code: 96 Type: Flickr API error Details: Invalid signature
I haven’t had a chance to capture what’s being sent yet and decipher where the problem lies. I’ve emailed the author to see if he knows any more but haven’t received a reply yet.
Comments Off
