![](/img/trans.png)
[英]Laravel/Socialite: Class Laravel\Socialite\Contracts\Factory does not exist
[英]Lumen + Socialite - Laravel\Socialite\Contracts\Factory is not instantiable
我想知道是否有人為 Lumen 實現了自定義社交名流提供程序。 我正在嘗試創建一個自定義提供程序,但沒有這樣做。 該錯誤似乎與 Google 搜索中發現的類似問題無關,但沒有一個對我有用。 我已經用盡了我所有的選擇。
以下是我用於提供程序的代碼
bootstrap/app.php
$app->withFacades();
class_alias('Laravel\Socialite\Facades\Socialite', 'Socialite');
// socialite
$app->register(Laravel\Socialite\SocialiteServiceProvider::class);
app/Providers/AppServiceProviders.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Briovo\Providers\BriovoProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->registerBriovoSocialite();
}
private function registerBriovoSocialite()
{
$briovo = $this->app->make('Laravel\Socialite\Contracts\Factory');
/*$briovo->extend(
'briovo',
function ($app) use ($briovo) {
$config = $app['config']['services.briovo'];
return $briovo->buildProvider(BriovoProvider::class, $config);
}
);*/
}
}
app/Providers/BriovoProvider.php
<?php
namespace Briovo\Providers;
use Laravel\Socialite\Two\AbstractProvider;
use Laravel\Socialite\Two\ProviderInterface;
use Laravel\Socialite\Two\User;
class BriovoProvider extends AbstractProvider implements ProviderInterface {
protected $base_url = 'http://central.dev'
/**
* {@inheritdoc}
*/
protected function getAuthUrl($state)
{
return $this->buildAuthUrlFromBase( $base_url . '/authorize');
}
/**
* {@inheritdoc}
*/
protected function getTokenUrl()
{
return $base_url . '/oauth/token';
}
/**
* {@inheritdoc}
*/
public function getAccessToken($code)
{
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
'form_params' => [
'grant_type' => 'authorization_code',
'client_id' => 'client-id',
'client_secret' => 'client-secret',
'redirect_uri' => 'http://example.com/callback',
'code' => $code,
],
]);
return $this->parseAccessToken($response->getBody());
}
/**
* {@inheritdoc}
*/
protected function getTokenFields($code)
{
return array_add(
parent::getTokenFields($code), 'grant_type', 'authorization_code'
);
}
/**
* {@inheritdoc}
*/
protected function getUserByToken($token)
{
$response = $this->getHttpClient()->get( $this->base_url . '/api/me', [
'headers' => [
'Authorization' => 'Bearer ' . $token,
],
]);
return json_decode($response->getBody(), true);
}
}
app/Http/Controller/BriovoAuthController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Socialite;
class BriovoAuthController extends Controller
{
protected $provider_name = 'briovo';
public function redirectToProvider()
{
//return Socialite::driver($this->provider_name)->redirect();
}
public function handleProviderCallback()
{
// $user = Socialite::driver($this->provider_name)->stateless()->user();
}
}
我收到錯誤
BindingResolutionException
Target [Laravel\Socialite\Contracts\Factory] is not instantiable.
問題出在AppServiceProvider.php
文件中。
$briovo = $this->app->make('Laravel\\Socialite\\Contracts\\Factory');
正在失敗。 我試圖從boot()
方法調用此代碼,但沒有效果。
我知道代碼的其他部分現在可能不正確。 在我弄清楚這個問題后,我可以讓他們工作。 據我所知,我已經注冊了門面和別名就好了。
我嘗試使用社交名流提供程序生成器但我最終遇到了同樣的錯誤!
我已經按照流明的確切說明進行操作,但沒有用!
我在 laravel 5.5 中實現自定義社交派生器時發現了這個問題。 我已經在問題中提到的 laravel 5.4 中實現了自定義社交驅動程序並且它工作正常。
檢查以下 StackOverflow 問題的答案可能對您有所幫助。 下面一個解決了我的問題。
Laravel/Socialite:類 Laravel\\Socialite\\Contracts\\Factory 不存在
在app/providers/AppServiceProvider.php
里面
粘貼以下內容
public function register()
{
$this->app->singleton(\Illuminate\Contracts\Routing\ResponseFactory::class, function() {
return new \Laravel\Lumen\Http\ResponseFactory();
});
$this->app->bind(\Illuminate\Contracts\Routing\UrlGenerator::class, function ($app) {
return new \Laravel\Lumen\Routing\UrlGenerator($app);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.