每次用户登录时都应该生成oAuth中的访问令牌吗?

Should the access token in oAuth be generated every time the user logs in?(每次用户登录时都应该生成oAuth中的访问令牌吗?)
本文介绍了每次用户登录时都应该生成oAuth中的访问令牌吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经在 php 中实现了 oAuth(目前用于 twitter),正如我在几个教程中读到的,你应该将访问令牌存储在 db 中以备将来使用.但是,我不知道您如何知道您是否为特定用户存储了访问令牌,以决定是否应将其从数据库中取出或重新生成.这是描述我的问题的流程:

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:

  • 获取请求令牌
  • 将用户发送到提供商的身份验证页面
  • 用户使用 oauth 令牌和 oauth 验证器返回回调 url
  • 获取访问令牌
  • 在数据库上保存访问令牌/user_id/screen_name 以备将来使用
  • 如果用户没有注销,访问令牌仍然在服务器会话变量中.否则,重复过程.
  • 获取请求令牌
  • 将用户发送到提供商的身份验证页面
  • 用户使用 oauth 令牌和 oauth 验证器返回回调 url
  • (此时我只有 oauth 令牌,我如何知道用户之前是否使用 twitter 登录并从 db 中提取了他们的访问令牌?)
  • 如果是用户第一次登录,生成访问令牌.

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. 当用户登录时,我会检查他们在数据库中是否有令牌

  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 重试之后 twitter 仍然抱怨.有问题,通知管理员!

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

这是图形解释:

这篇关于每次用户登录时都应该生成oAuth中的访问令牌吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)