tags:

views:

73

answers:

3

On most API's such as facebook and bebo to use there API you must get a Key and secret, I am just wondering what is some good methods of doing a system like this. I will be using PHP/MysQL.

How can I basicly verify a user key and secret are ok when there app sends there API request? I was thinking of storing them in mysql, which I will have them stored there no matter what but I was wondering if there is some other method that is better for the verification process, instead of hitting the DB on every single API hit?

+1  A: 

If the key is an encrypted form of the domain and secret they're using, you wouldn't need to hit the db to verify them.

if ($key != encrypt($domain . $secret))
    // die
Jonathan Sampson
I should add each API user would have it's own secret, would that break this?
jasondavis
No, just so long as the key is the result of their secret and their domain.
Jonathan Sampson
A: 

Cache the auth info in memcached and you'll save reads in the db.

NA
A: 

you'll need somewhere to keep the key/secret combo. i think its impossible not to have a db hit unless you use some sort of caching like memcached.

in regards to they key/secret implementation, several places use a public/private key combo. you encrypt they data with the private key, then send it across where it's decrypted with the public key (or vice versa). I think the openssl package has this functionality.

http://php.net/manual/en/book.openssl.php

-d

dw
Many of these services "sign" the request, rather than encrypting the whole thing. The goal is simply to verify that the request was generated by the application owner, and not an attacker; protecting the content of the request from prying eyes is not a priority. And verifying a signature can be less taxing for the API provider than decrypting entire messages.
Frank Farmer