I am trying to implement a thing like OAuth in PHP and what I want to do is give tokens to users so they can use their private resources. Every user first must login with their email and password and get a unique token which would be valid forever unless it's idle for "n" minutes. So if there are zero requests for "n" minutes, the token should be destroyed. The token would be used to access private resources by users.
One thing I can think of doing this is as...
I would maintain a db table of named user_tokens and as they login with their username and password the entry with unique token would be created there. The last accessed timestamp would be set and user would given the unique token as response. The token now can be used to access private resources of user and would be required to pass with all request requiring token. Every private request would check if the last timestamp and current timestamp has "n" minutes of difference, if yes, destroy token. Otherwise send response with requested resources and set last timestamp to current timestamp.
Does that make sense? Or there can be another efficient way of doing this?
I would like to add that the token must be like what twitter or facebook returns out of their API.