php_cas_server
php_cas_server copied to clipboard
how to use plugin center?
how to use plugin center? for google/weibo
please check https://github.com/leo108/php_cas_server_oauth_weibo for reference
php_cas_server_oauth_weibo I have installed.
config/app.php
'providers' => [
....
Leo108\CASServer\OAuth\Weibo\CASOAuthWeiboServiceProvider::class,
],
app/Interactions/UserLogin.php
public function showLoginPage(Request $request, array $errors = [])
{
dd(app(PluginCenter::class)->getAll());
return view(
'auth.login',
[
'errorMsgs' => $errors,
'plugins' => app(PluginCenter::class)->getAll(),
'service' => $request->get('service', null),
]
);
}
Result on browser []
Put this code in App\Providers\AppServiceProvider::register
$this->app->bind(
'cas.server.weibo',
function () {
return (new Overtrue\Socialite\SocialiteManager(
[
'weibo' => [
'client_id' => 'your-app-id',
'client_secret' => 'your-app-secret',
],
]
))->driver('weibo');
}
);
run
php artisan vendor:publish --provider="Leo108\CASServer\OAuth\Weibo\ CASOAuthWeiboServiceProvider" --tag="migrations"
and
php artisan migrate
Socialite requires a "redirect", if not provided, an error will occur.
1/1
ErrorException in SocialiteManager.php line 240:
Undefined index: redirect
in SocialiteManager.php line 240
at HandleExceptions->handleError('8', 'Undefined index: redirect', '/home/lijiahao/Code/php_cas_server/vendor/overtrue/socialite/src/SocialiteManager.php', '240', array('config' => array('client_id' => 'your-app-id', 'client_secret' => 'your-app-secret'))) in SocialiteManager.php line 240
at SocialiteManager->formatConfig(array('client_id' => 'your-app-id', 'client_secret' => 'your-app-secret')) in SocialiteManager.php line 150
at SocialiteManager->createDriver('weibo') in SocialiteManager.php line 109
at SocialiteManager->driver('weibo') in AppServiceProvider.php line 70
at AppServiceProvider->App\Providers\{closure}(object(Application), array()) in Container.php line 731
at Container->build(object(Closure), array()) in Container.php line 629
at Container->make('cas.server.weibo', array()) in Application.php line 697
at Application->make('cas.server.weibo') in CASOAuthWeiboServiceProvider.php line 51
at CASOAuthWeiboServiceProvider->checkBound('cas.server.weibo', 'Overtrue\Socialite\Providers\AbstractProvider') in CASOAuthWeiboServiceProvider.php line 25
at CASOAuthWeiboServiceProvider->register() in Application.php line 554
at Application->register(object(CASOAuthWeiboServiceProvider)) in ProviderRepository.php line 74
at ProviderRepository->load(array('Illuminate\Auth\AuthServiceProvider', 'Illuminate\Broadcasting\BroadcastServiceProvider', 'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Foundation\Providers\FoundationServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Pipeline\PipelineServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'App\Providers\AppServiceProvider', 'App\Providers\AuthServiceProvider', 'App\Providers\EventServiceProvider', 'App\Providers\RouteServiceProvider', 'Fideloper\Proxy\TrustedProxyServiceProvider', 'Leo108\CAS\CASServerServiceProvider', 'Leo108\CASServer\OAuth\Weibo\CASOAuthWeiboServiceProvider')) in Application.php line 530
at Application->registerConfiguredProviders() in RegisterProviders.php line 17
at RegisterProviders->bootstrap(object(Application)) in Application.php line 203
at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 232
at Kernel->bootstrap() in Kernel.php line 127
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53
at require_once('/home/lijiahao/Code/php_cas_server/public/index.php') in server.php line 21
At present I write like this to fix the issue, is there a better way to get this redirect route?
$this->app->bind(
'cas.server.weibo',
function () {
return (new SocialiteManager(
[
'weibo' => [
'client_id' => 'your-app-id',
'client_secret' => 'your-app-secret',
'redirect' => "oauth/" . $this->app->make(WeiboPlugin::class)->getFieldName() . "/callback",
],
]
))->driver('weibo');
}
);
@rikakomoe just set redirect
to an empty string should fix this problem, we will call redirect()
method with final callback url here.
That doesn't work. The request in Leo108\CASServer\OAuth\Weibo\Plugins\WeiboPlugin::getOAuthUser requires a "redirect_uri" too, otherwise you get an error like this,
1/1
AuthorizeFailedException in AbstractProvider.php line 439:
Authorize Failed: {"error":"redirect_uri_mismatch","error_code":21322,"request":"\/2\/oauth2\/access_token","error_uri":"\/2\/oauth2\/access_token"}
in AbstractProvider.php line 439
at AbstractProvider->parseAccessToken(object(Stream)) in AbstractProvider.php line 264
at AbstractProvider->getAccessToken('ea6a206c387abdb7e44fa82659b2890d') in AbstractProvider.php line 185
at AbstractProvider->user() in WeiboPlugin.php line 51
at WeiboPlugin->getOAuthUser(object(Request)) in OAuthController.php line 54
at OAuthController->callback('weibo_id', object(Request))
However by no means could this redirect uri be figured out. I guess it is some design issue with Leo108\CASServer\OAuth\Plugin::getOAuthUser, which should probably request a parameter "callback" too. Or maybe there are better ways instead?
@rikakomoe yes you are right, add a callback
parameter to getOAuthUser
method is a solution, I'll handle this.
@rikakomoe fixed at 151dd48a749f989530af97798dce704695fc5870 , thanks for your reporting.
@leo108 Please also update these two packages to avoid broken dependencies. https://github.com/leo108/php_cas_server_oauth_weibo/blob/592d659534d3ab1895c4eb826eeff2af250e74a4/composer.json#L20 https://github.com/leo108/php_cas_server_oauth_wechat/blob/89d17c8d2d95e97672f3f26a5e3f0061dd420410/composer.json#L21
@rikakomoe just forgot to push, done