Note that there are some explanatory texts on larger screens.

plurals
  1. PORESTful API with HMAC: how to manage user authentication
    primarykey
    data
    text
    <p>I am developing a RESTful API for my web and mobile applications. My intention with this API is to store all data of users so that my applications can access them easily. It is like Google's solution: you don't have a separate account for Gmail and Youtube, but a shared one.</p> <p>For every request (that needs USER authentication, not only APPLICATION authentication) the following workflow is applied:</p> <ul> <li><p>Application determines the message of the request:<br/> MESSAGE= URL + HEADERS + BODY</p></li> <li><p>Application calculates the signature of the request:<br/> SIGNATURE= HMAC(HMAC(MESSAGE, user_password), application_key)<br/></p></li> <li><p>Application sends the request via HTTP/HTTPS:<br/> REQUEST= MESSAGE + Signature</p></li> <li><p>API recreates the signature to authenticate both user and application:<br/> SIGNATURE= application_id/user_id HMAC(HMAC(MESSAGE, user_password_from_database), application_key)</p></li> </ul> <p>Where e.g.:<br/></p> <ul> <li><p>application_id = 1</p></li> <li><p>user_id = 123456</p></li> <li><p>user_password= 'mypass'</p></li> <li><p>user_password_from_database= '$2y$10$1234567890abcde...'</p></li> </ul> <p>The problem with this approach is that passwords in the database are irreversibly hashed (with BCrypt), and that's why I can't use them when I want to the recreate the signature of the request.</p> <p>My question is how it can be accomplished yet? Is sending user_password_from_database to the application via HTTPS a good practice? My basic workflow would be:</p> <ul> <li><p>User logs in to the application with user_email and user_password</p></li> <li><p>Application sends these credentials via HTTPS to the API</p></li> <li><p>API responds with user_id and user_password_from_database if credentials are OK</p></li> <li><p>From now, application can use these data to determine SIGNATURE.</p></li> <li><p>From now, API can recreate SIGNATURE because user_password_from_database is the secret key, not user_password</p></li> </ul> <p>How secure is this algorithm? Does HTTPS prevent abuse of user_password_from_database?</p> <p>Footnote: the signing method detailed above is just an example, indeed I took Amazon's <a href="http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html" rel="nofollow">AWS Signature Version 4</a> algorithm and tried to add some user authentication to it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload