我想知道是否有人为Lumen实施了自定义社交网站提供商。我正在尝试创建自定义提供程序但未能这样做。这个错误似乎与谷歌搜索中发现的类似问题有关,但它们都不适用于我。我已经筋疲力尽了所有的选择。
以下是我用于提供商的代码
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()
方法调用此代码,但它没有任何效果。
我知道代码的其他部分现在可能不正确。在弄清楚这个问题后,我可以让他们上班。据我所知,我已经注册了外观和别名就好了。
我尝试使用socialite provider generator但我最终遇到了同样的错误!
我已按照流明的确切说明但没有用!
答案 0 :(得分:0)
我在laravel 5.5中实现自定义社交派生时发现了这个问题。我已经在问题中提到的laravel 5.4中实现了自定义社交驱动程序,并且其工作正常。
检查下面StackOverflow问题的答案可能会对您有所帮助。下面就解决了我的问题。
Laravel/Socialite: Class Laravel\Socialite\Contracts\Factory does not exist
答案 1 :(得分:0)
里面
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);
});
}