首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Oriceon OAuth Laravel 5-调用未定义方法OAuth::Call ()

Oriceon OAuth Laravel 5-调用未定义方法OAuth::Call ()
EN

Stack Overflow用户
提问于 2016-11-07 09:37:33
回答 1查看 530关注 0票数 1

我正在为Laravel 5 OAuth实现oriceon/oauth-5-laravel服务提供商

我收到了这个错误“调用未定义的方法OAuth::this ()”。我遵循自述安装步骤:

  • 我在composer.json中添加了"oriceon/oauth-5-laravel":"dev-master“。然后我运行composer更新,没有错误。
  • 我在'providers‘数组中添加了"Artdarek\OAuth\OAuthServiceProvider::class“
  • 我在OAuth中的“别名”数组中添加了“=>‘=> Artdarek\OAuth\Facade\OAuth::class”

以下是我的config/oauth-5-laravel.php:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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);
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-11 14:17:00

问题是在php中是类OAuth,它是在oriceons OAuth之后被初始化的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40461932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档