1
我採取的OAuth服務提供商Laravel 5 oriceon/oauth-5-laravelOriceon的OAuth Laravel 5 - 調用未定義的方法的OAuth ::消費者()
我得到這個錯誤 「調用未定義的方法的OAuth ::消費者()」。 我以下自述步驟進行安裝:
我已經加入 「oriceon/OAuth的5- laravel」: 「DEV-主」 到composer.json。然後我運行作曲家更新,沒有錯誤。
我已經加入 「Artdarek \ OAuth的\ OAuthServiceProvider ::類,」 到 '提供者' 陣列app.php
我已經加入「 '的OAuth'=> Artdarek \的OAuth \門面\的OAuth ::類,」到 '變體' 在app.php
這裏陣列是我的配置/ 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);
}
}
}