【问题标题】:Why does Facebook auth redirect cause server error?为什么 Facebook 身份验证重定向会导致服务器错误?
【发布时间】:2013-01-10 21:55:04
【问题描述】:

我在 codeigniter 中构建了一个简单的 url 缩短应用程序,它还允许用户通过 facebook 登录。

第一次授权时,它在允许 facebook 权限后返回服务器错误。

我已将问题缩小到我的路由文件或我的 htaccess。但无论我怎么尝试,我都无法让它发挥作用。

由于应用程序是 url 更短,任何未指定的路由都使用默认路由。就这样……

$route['login'] = "auth/login";
$route['about'] = "pages/about";
$route['(:any)'] = "redirect/index/$1"; 

我认为这就是它无法通过身份验证的原因。我试着做:

$route['auth_social/(:any)'] = "auth_social/$1";

这也不起作用。我唯一可以让它工作的时间是如果我将我的 .htaccess 更改为

RewriteEngine on
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteRule ^(.*)$ /index.php/$1 [L]

但是我的网址缩短会中断并且不起作用。快把我逼疯了。

有人能看出我哪里出错了吗?

这是我的完整 .htaccess 文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

编辑:

这是来自服务器日志的错误:

 [10-Jan-2013 11:02:25 UTC] PHP Fatal error:  Uncaught OAuthException: An active access token must be used to query information about the current user.
  thrown in /Users/mycomputer/Documents/grpe/app/application/libraries/facebook/base_facebook.php on line 1058

【问题讨论】:

  • 实际错误信息是什么? (检查您服务器的日志文件!)
  • 好的。我在osx上使用mamp。我如何找到我的日志文件?
  • 这就是我的想法——只是使用 PHP SDK 时未捕获的异常。所以很可能它没有连接到您的路由,而是连接到您的应用程序逻辑。
  • 好的,但是当我更改我的 htaccess 文件时,它确实可以工作,但会破坏缩短部分。你有什么建议?
  • 可能是 cookie 路径的问题 - 如果 SDK 没有获得所需的 cookie 值,因为它在当前 HTTP 路径下无效,这可能解释了为什么它会在您的路由中失败而不是否则。

标签: facebook .htaccess codeigniter routes


【解决方案1】:

您使用的是什么 oAuth 库?

我强烈推荐使用这个 oAuth2 sparks 库:
http://getsparks.org/packages/oauth2/versions/HEAD/show

我已经使用了一段时间了,登录/注册完全没有问题。

HTH

【讨论】:

  • 谢谢。我使用的是修改版的 tank auth。
猜你喜欢
  • 2019-06-24
  • 2016-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-24
  • 2016-04-02
相关资源
最近更新 更多