Token authentication - where to store the token

前端 未结 1 769
春和景丽
春和景丽 2021-01-21 08:29

I am working with PHP and Laravel at the moment, I have a restful api that the user needs to authenticate with to make sure they can only access things they own etc.

Wha

相关标签:
1条回答
  • 2021-01-21 09:06

    I suggest to go the following route:

    1. the user logs into your site and requests a API usage token
    2. when a new request to your API comes in, compare the token from the incomming request, with the token in the db. if it is found, it's a valid request. the REST client could use the Authorization header to send the token.
    3. send the answer for the request

    While the login system of your website, might be session-based with cookies on client-side, the REST API is token-based and doesn't need a cookie or session.

    Please take a look at this for more details: https://softwareengineering.stackexchange.com/a/141434/111803

    0 讨论(0)
提交回复
热议问题