Google OAuth2 在本地开发服务器上不起作用 - PHP Codeigniter spark

2022-08-30 14:17:48

我正在尝试使用Codeigniter spark(http://getsparks.org/packages/oauth2/versions/HEAD/show)来允许用户使用fb和google登录到我的php站点。

我的本地开发站点(在wampserver上)被称为 mysite.dev,为此我有一个等/主机文件,例如:

127.0.0.1       mysite.dev

Facebook登录工作绝对正常。但是当我尝试使用Google登录时,google抱怨:redirect_uri的参数值无效:不允许非公共域:http://mysite.dev/index.php/oauth2/session/google 其中oauth2是我的控制器,会话是我指定fb / google等的函数

任何线索/提示?


答案 1

我通过为域添加一个主机文件记录来解决这个问题,开发部分位于前面而不是末尾(我通常也会这样做):

/etc/hosts

127.0.0.1 localhost.mydomain.com

/etc/apache vhost

ServerName mydomain.com.localhost
ServerAlias localhost.mydomain.com

然后告诉谷歌使用:

http://localhost.mydomain.com/index.php/oauth2/session/google

答案 2

在 Google API 控制台中为 Web 应用创建客户端 ID 时,可以添加“允许”。它也接受网址和其他。Redirect URIslocalhost


推荐