Question

I'm writing REST API in PHP and recently I faced with authorization problem. I read a lot about basic authorization, about using private and public keys to create request signature. It is said that using request signature is more secure. But then I have a question:

-How should user will pass public key and generated signature?

I'm thinking about several options:

1) Create custom http header like X-Key, X-Signature

2) Use authorization header with custom scheme, like

AUTHORIZATION: SIGNATURE key='123' signature='abc'

3) Send this values as parameters. But I don't know if it acceptable for methods DELETE and PUT

What would you advice?

p.s. I don't want to implement oAuth

Was it helpful?

Solution

What are the desired properties of authentication scheme? Is this a publicly accessible or an intranet service? Are user accounts linked to something outside of scope of your API (linked 3rd party accounts etc). How are you going to distribute user credentials?

I would probably stick with plain old basic authorization, but encrypt everything at the transport level, making use of HTTPS mandatory. Rolling out your own cryptographic scheme is generally not a good idea. It's easier to fall victim to timing or replay attack than it seems. If you insist on client using a key pair for authentication, you can use HTTPS client certificates (though this is not widely used and maybe somewhat cumbersome solution).

There are a few security concerns about plain-text authentication over TLS. First, if someone implements MITM with forged certificate using either well known CA (maybe a government agency) or CA the client is forced to trust (big evil corporate proxy), they will get credentials. But you can't protect the client from its own environment anyway. Second, basic authentication can be prone to CSRF because browser knows how to do it and can remember credentials if you presented challenge and user filled the form. That's not a big problem if you adhere to REST principles and never allow state-changing GET requests. Also, if you are using JSON, never return arrays.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top