我正在尝试Hybrid Auth,但我不知道为什么这不起作用。
我拥有 index.php
中的所有内容<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$app = new \Slim\App();
// facebook api
define('FACEBOOK_APP_ID','1583449111670664');
define('FACEBOOK_APP_KEY','c673d4ec188b72d00a31388d2d31bfdc');
$container = $app->getContainer();
$container['hybrid-api'] = function($c) {
$settings = [
'base_url' => 'http://localhost/hybrid-auth/auth',
'providers' => [
'Facebook' => [
'enabled' => true,
'keys' => ['id' => FACEBOOK_APP_ID, 'secret' => FACEBOOK_APP_KEY],
'scope' => ['id','name','first_name','last_name','link','locale','email'],
'trustForwarded' => true
]
],
'debug_mode' => 'info',
'debug_file' => 'logs/hybrid-auth.log',
];
return new Hybrid_Auth($settings);
};
$app->get('/', function(Request $request, Response $response){
$hybrid = $this->get('hybrid-api');
$session_user = Hybrid_Auth::storage()->get('user');
if( empty($session_user) ) {
echo "<a href='/hybrid-auth/login'>login</a>";
} else {
echo "Welcome " . $session_user->displayName . "<br />";
}
});
$app->get('/login', function(Request $request, Response $response){
$hybrid = $this->get('hybrid-api');
$adapter = $hybrid->authenticate(ucwords('facebook'));
$user_profile = $adapter->getUserProfile();
if( empty( $user_profile ) ) {
echo 'Error!!';
} else {
Hybrid_Auth::storage()->set('user', $user_profile);
return $response->withRedirect('/hybrid-auth');
}
});
$app->get('/auth', function(Request $request, Response $response){
Hybrid_Endpoint::process();
});
$app->run();
composer.json
"require": {
"slim/slim": "^3.0",
"hybridauth/hybridauth": "2.8.2"
}
我正在apache2上运行它作为文件夹。 http://localhost/hybrid-auth
我不会提取Facebook应用程序ID和密钥,因为它是一个测试应用程序。
错误
在Hybrid Auth日志中,一切正常。没有错误消息。