事实上,我正在从事CakePHP3项目,我想添加社交登录: Facebook,Google.
我找到了完成所有这些任务的CakeDC插件。
我正确地安装了插件并配置了它,简单的登录可以工作,但是我在Facebook和Google上遇到了麻烦。
我在Facebook和Google控制台上创建了一个项目,并给他们提供了以下urls:
http://projettest.com/auth/facebook
http://projettest.com/auth/google
我把这个添加到我的bootstrap.php中:
Configure::write('OAuth.providers.facebook.options.clientId', '866098280167491');
Configure::write('OAuth.providers.facebook.options.clientSecret', 'secret');
Configure::write('OAuth.providers.google.options.clientId', '772409145076-birdmh5a3t48b8mg9knq0lonup6aeomk.apps.googleusercontent.com');
Configure::write('OAuth.providers.google.options.clientSecret', 'secret');当我试图与他们一起登录时,我接受使用我的Facebook和Google acounts登录,但之后出现了这样一条消息:
您无权访问该位置。
如果检查请求,我看到一个来自Google和Facebook的响应,它有代码参数,例如:state=xxx&prompt=consent#
这是permission.php的内容:
return [
'Users.SimpleRbac.permissions' => [
[
'role' => '*',
'plugin' => 'CakeDC/Users',
'controller' => '*',
'action' => '*',
],
[
'role' => 'user',
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => ['register', 'edit', 'view'],
],
[
'role' => 'user',
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => '*',
'allowed' => true,
],
[
'role' => ['user'],
'controller' => ['Pages'],
'action' => ['other', 'display'],
'allowed' => true,
],
]];这是users.php的内容
$config = [
'Users' => [
//Table used to manage users
'table' => 'CakeDC/Users.Users',
//configure Auth component
'auth' => true,
//Password Hasher
'passwordHasher' => '\Cake\Auth\DefaultPasswordHasher',
//token expiration, 1 hour
'Token' => ['expiration' => 3600],
'Email' => [
//determines if the user should include email
'required' => true,
//determines if registration workflow includes email validation
'validate' => true,
],
'Registration' => [
//determines if the register is enabled
'active' => true,
//determines if the reCaptcha is enabled for registration
'reCaptcha' => true,
],
'Tos' => [
//determines if the user should include tos accepted
'required' => true,
],
'Social' => [
//enable social login
'login' => false,
],
'Profile' => [
//Allow view other users profiles
'viewOthers' => true,
'route' => ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'profile'],
],
'Key' => [
'Session' => [
//session key to store the social auth data
'social' => 'Users.social',
//userId key used in reset password workflow
'resetPasswordUserId' => 'Users.resetPasswordUserId',
],
//form key to store the social auth data
'Form' => [
'social' => 'social'
],
'Data' => [
//data key to store the users email
'email' => 'email',
//data key to store email coming from social networks
'socialEmail' => 'info.email',
//data key to check if the remember me option is enabled
'rememberMe' => 'remember_me',
],
],
//Avatar placeholder
'Avatar' => ['placeholder' => 'CakeDC/Users.avatar_placeholder.png'],
'RememberMe' => [
//configure Remember Me component
'active' => true,
'Cookie' => [
'name' => 'remember_me',
'Config' => [
'expires' => '1 month',
'httpOnly' => true,
]
]
],
],
//default configuration used to auto-load the Auth Component, override to change the way Auth works
'Auth' => [
'loginAction' => [
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => 'login',
'prefix' => false
],
'authenticate' => [
'all' => [
'scope' => ['active' => 1]
],
'CakeDC/Users.ApiKey',
'CakeDC/Users.RememberMe',
'Form',
],
'authorize' => [
'CakeDC/Users.Superuser',
'CakeDC/Users.SimpleRbac',
],
],
'OAuth' => [
'path' => ['plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'socialLogin', 'prefix' => false],
'providers' => [
'facebook' => [
'className' => 'League\OAuth2\Client\Provider\Facebook',
'options' => [
'graphApiVersion' => 'v2.5',
'redirectUri' => Router::url('/auth/facebook', true)
]
],
'twitter' => [
'options' => [
'redirectUri' => Router::url('/auth/twitter', true)
]
],
'linkedIn' => [
'className' => 'League\OAuth2\Client\Provider\LinkedIn',
'options' => [
'redirectUri' => Router::url('/auth/linkedIn', true)
]
],
'instagram' => [
'className' => 'League\OAuth2\Client\Provider\Instagram',
'options' => [
'redirectUri' => Router::url('/auth/instagram', true)
]
],
'google' => [
'className' => 'League\OAuth2\Client\Provider\Google',
'options' => [
'userFields' => ['url', 'aboutMe'],
'redirectUri' => Router::url('/auth/google', true)
]
],
],
]
];
return $config;请帮帮我。
发布于 2016-04-01 23:46:34
如果cURL调用有问题,则SocialAuthenticate _authenticate函数返回false并重定向到登录页面。检查服务器SSL设置。在$e->getMessage()中,您会发现错误。发行:https://github.com/CakeDC/users/issues/348
https://stackoverflow.com/questions/36175984
复制相似问题