CSRF 状态令牌与提供的 FB PHP SDK 3.1.1 Oauth 2.0 不匹配 [英] CSRF state token does not match one provided FB PHP SDK 3.1.1 Oauth 2.0

查看:21
本文介绍了CSRF 状态令牌与提供的 FB PHP SDK 3.1.1 Oauth 2.0 不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器日志显示CSRF 状态令牌与提供的令牌不匹配"错误,这似乎几乎发生在每个用户身上.但是,用户已创建和/或经过身份验证,我能够检索用户信息.我正在使用带有 Apache 的 Linux 服务器.我也在使用最新的 Facebook PHP SDK v.3.1.1 谁能告诉我为什么会发生这种情况以及如何解决它?

解决方案

上周我遇到了类似的问题,并追踪到 state 字段被多次调用 getLoginUrl 覆盖().每次调用 getLoginUrl() 时,SDK 中都会生成一个新的 state 令牌并存储在 $_SESSION 中(它只是一个随机值),因此如果您调用它两次并且用户使用第一个链接登录,第二次调用将重置 SDK 的内部 state 令牌,并且您将在日志中收到此错误.

SDK 在 Facebook 授权用户后返回的 URL 中查找相同的 state 令牌并将他们重定向回您的网站,如果不匹配,它将记录此错误(这里是来源的链接.

My server logs show a "CSRF state token does not match one provided" error which seems to happen for almost every user. However, the users are created and/or authenticated and I am able to retrieve the user info. I am using a Linux server with Apache. I am also using the latest Facebook PHP SDK v.3.1.1 Can anyone tell me why this is happening and how to fix it?

解决方案

I had a similar issue last week, and tracked it down to the state field being overwritten by multiple calls to getLoginUrl(). Each time you call getLoginUrl(), a new state token is generated in the SDK and stored in the $_SESSION (it's just a random value), so if you call it twice and the user uses the first link to log in, the second call will have reset the SDK's internal state token, and you will get this error in your logs.

The SDK looks for the same state token in the URL coming back after Facebook authorizes the user and redirects them back to your site, and if it doesn't match it will log this error (here's a link to the source).

这篇关于CSRF 状态令牌与提供的 FB PHP SDK 3.1.1 Oauth 2.0 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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