K
K
kappka2020-04-24 22:42:55
PHP
kappka, 2020-04-24 22:42:55

How to implement API tokens in PHP?

Hello.
I am writing an API to integrate with the service.
The interaction scheme is as follows:
1. The Iframe client on my site sends requests to their server.
2. Their server is knocking on the API to me for all operations.

From the docs:
"There must be 2 tokens for each user. The first is for requesting authentication, getting user data, and getting a 2nd token. The second for other operations. Tokens must be unique for each user and have a limited lifetime (60 minutes)."

Tell me, please, is it the right decision to store tokens for each user in the database table? With information about the time of their creation, to update after 60 minutes
That is, I take a token for the user from the database, send it to the iframe during initialization, then their server knocks on API, I check the first token, if everything is ok, I issue the second one, if the period has expired, I update it. Same story with the second one.

And tell me, please, what is the best way to generate these tokens using php?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question