Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use plugin center? #13

Open
sugengsuprayogi opened this issue Nov 21, 2017 · 10 comments
Open

how to use plugin center? #13

sugengsuprayogi opened this issue Nov 21, 2017 · 10 comments

Comments

@sugengsuprayogi
Copy link

how to use plugin center? for google/weibo

@leo108
Copy link
Owner

leo108 commented Nov 21, 2017

please check https://github.com/leo108/php_cas_server_oauth_weibo for reference

@sugengsuprayogi
Copy link
Author

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
[]

@leo108
Copy link
Owner

leo108 commented Nov 21, 2017

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

@satouriko
Copy link
Contributor

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');
            }
        );

@leo108
Copy link
Owner

leo108 commented May 28, 2018

@rikakomoe just set redirect to an empty string should fix this problem, we will call redirect() method with final callback url here.

@satouriko
Copy link
Contributor

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?

@leo108
Copy link
Owner

leo108 commented May 29, 2018

@rikakomoe yes you are right, add a callback parameter to getOAuthUser method is a solution, I'll handle this.

@leo108
Copy link
Owner

leo108 commented May 29, 2018

@rikakomoe fixed at 151dd48 , thanks for your reporting.

@leo108
Copy link
Owner

leo108 commented May 29, 2018

@rikakomoe just forgot to push, done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants