Home > Back-end >  Flutter-What is the point of using bearer-token or something
Flutter-What is the point of using bearer-token or something

Time:05-14

I read something like this: 1-Once a user logs in, you can generate a token and store it in MySQL database and share the same token with the response of login API. 2-Store the token using shared-preferences. 3-When a user opens the app, check if the token exists if it does, then send the token with all the APIs inside the request header which requires the user to be logged in.

But what is the point of using token if i was keeping it in database.Eventually this token related with userid and with this userid everthing can be reachable.So I want to ask why should I use some token to keep user loged in instead of user email or something.

CodePudding user response:

Using token is much more secure and useable. Storing just token more secure becase in case of leak, the token can be revoked or something. On the other side storing user's username and password is security risk. Also, most of the services use tokens on their API's and there is no username pass authorization. For example whole OAuth2 concept is built on top of this. In short, tokens are much more secure and flexible.

CodePudding user response:

Optimal usage of bearer token using as a set with an access token and refresh token. While you are passing access token on header while you are making HTTP request typically access token dies frequently especially when security is a prominent feature of the app, like banking apps. When a user makes an HTTP request and if the access token is dead then you should refresh it via another API call with the refresh token and return the same API call with the new access token.

  • Related