应的OAuth访问令牌生成每次用户登录? [英] Should the access token in oAuth be generated every time the user logs in?

查看:674
本文介绍了应的OAuth访问令牌生成每次用户登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了在PHP(目前微博)的OAuth的,当我在几个教程读过你应该存储在数据库的访问令牌以备将来使用。但是我不明白你怎么知道你是否有存储为特定用户来决定是否应该将其拉出分贝或重新生成访问令牌。这里是描述我的问题一个流程:

I've implemented the oAuth in php (currently for twitter) and as I've read in several tutorials you should store the access token in db for future use. However I don't see how you know if you have the access token stored for a particular user to decide if you should pull it out of the db or regenerate it. Here's a flow describing my question:


  • get请求令牌

  • 发送用户提供的身份验证页

  • 用户返回到回调通过OAuth令牌和OAuth验证网址

  • 获得访问令牌

  • 在DB
  • 保存访问令牌/ USER_ID / SCREEN_NAME以供日后使用


  • 访问令牌仍然在服务器会话瓦尔如果用户没有注销。否则,重复的过程。


  • get请求令牌

  • 发送用户提供的身份验证页

  • 用户返回到回调通过OAuth令牌和OAuth验证网址

  • (在这一点上我只有OAuth凭证,我怎么能知道用户是否具有previously与Twitter登录并拉离分贝的访问令牌?)

  • 如果它是用户的第一洛,产生访问令牌。

有关OAuth的主要工作流程是明确的,但目前尚不清楚如何处理老用户以及哪些数据应该存储或没有。

The main workflow for oAuth is clear, however it is not clear how to handle returning users and which data should be stored or not.

一个亿的感谢!

推荐答案

您不应该重新对每个访问令牌。生成它,只有当它过期。我已经使用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访问令牌生成每次用户登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆