views:

38

answers:

2

I want to make nice and clean api; I'm making site and I want to offer the ability to mobile apps use web API of my site.

I don't want to use oAuth, becouse the mobile and embedded applications that are facing the biggest hurdle, as they may not be able to bring up and/or control the web browser. Also its a little complicate.

I know, that HTTP basic authorisation is not safe, but it's so simple... I want to use it in my api. I have somee users logins and their passwords (md5-encoded) in mysql base, but how to use those data in this HTTP basic authorisation?

A: 

The PHP manual has an example
Jus google your question "PHP HTTP basic" and here you are
http://php.net/manual/en/features.http-auth.php

it is as simple as sending a few HTTP headers.

Also note that digest authorization considered to be more safe but less compatible with clients.

Col. Shrapnel
A: 

Generate a random unique string for each user in your database and make that string available to the end users. When they access the api ask them to enter that unique string that you supplied--this is their 'key'. Each time a users app accesses the api they pass the key which links directly to a unique account and that is how you authorize them. It is essentially user name and password all in one.

While the above example is generic you should also take things like security into account--for example, when possible, pass the device ID from the mobile along and use that during authentication, or use their current password hash during their API key generation so if they change their password the key will stop working and they have to get a new one--this way they can control access if their key is lost.

It doesn't have to be complicated, it just has to be safe. =)

angryCodeMonkey
It seems to be very good idea, thank you very much :)
monthon1