且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应的OAuth访问令牌生成每次用户登录?

更新时间:2023-02-16 09:13:42

您不应该重新对每个访问令牌。生成它,只有当它过期。我已经使用OAuth构建Twitter应用程序。在这里,我的流程:

You should not regenerate token for each access. Generate it only when it's expired. I've build twitter application using OAuth. Here my flow:


  1. 当用户登录,我会检查他们是否有在DB令牌

  1. when user login, I will check if they have token in DB

1.1。如果它不存在,验证他们的身份,然后存储和使用所产生的标记

1.1. If it's not exists, authenticate them and then store and use the resulting token

1.2。如果它的存在,使用它。

1.2. If it's exists, use it.

1.2.1。如果Twitter不抱怨,那么令牌仍然有效,使用它。

1.2.1. If twitter doesn't complain, then the token still valid, use it.

1.2.2。如果Twitter抱怨,那么令牌已过期。返回到1.1。

1.2.2. If twitter complained, then the token is expired. Return to 1.1.

1.2.3。如果在x重试仍然叽叽喳喳抱怨。不对劲,通知管理员!

1.2.3. If after x retry twitter still complained. Something wrong, notify admin!

下面的图形说明:

应的OAuth访问令牌生成每次用户登录?