我正在为Laravel 5 oriceon/oauth-5-laravel
实施OAuth服务提供商我收到此错误"调用未定义的方法OAuth :: consumer()"。 我正在按照安装的自述步骤进行操作:
我添加了" oriceon / oauth-5-laravel":" dev-master"到composer.json。然后我运行composer update,没有错误。
我添加了" Artdarek \ OAuth \ OAuthServiceProvider :: class,"进入'提供商' array app.php
我添加了"' OAuth' => Artdarek \的OAuth \门面\ OAuth的::类,"进入'别名' app.php中的数组
这是我的config / oauth-5-laravel.php:
return [
/*
|--------------------------------------------------------------------------
| oAuth Config
|--------------------------------------------------------------------------
*/
/**
* Storage
*/
'storage' => '\\OAuth\\Common\\Storage\\Session',
/**
* Consumers
*/
'consumers' => [
'Facebook' => [
'client_id' => '',
'client_secret' => '',
'scope' => [],
],
'Google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_SECRET_ID'),
'scope' => ['userinfo_email', 'userinfo_profile'],
],
]
];
这是我的GoogleController.php:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use OAuth;
class GoogleController extends Controller
{
public function loginWithGoogle(Request $request)
{
// get data from request
$code = $request->get('code');
// get google service
$googleService = \OAuth::consumer('Google');
// check if code is valid
// if code is provided get user data and sign in
if ( ! is_null($code))
{
// This was a callback request from google, get the token
$token = $googleService->requestAccessToken($code);
// Send a request with it
$result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
$message = 'Your unique Google user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
echo $message. "<br/>";
//Var_dump
//display whole array.
dd($result);
}
// if not ask for permission first
else
{
// get googleService authorization
$url = $googleService->getAuthorizationUri();
// return to google login url
return redirect((string)$url);
}
}
}
答案 0 :(得分:0)
问题在于,php是类OAuth,它是在oriceons OAuth之后被反对的。