【发布时间】:2018-10-04 02:51:21
【问题描述】:
这适用于 laravel 5.2,但在 5.6 中我没有访问方法和方法获取,没有重定向。
【问题讨论】:
-
你解决了吗?我也有兴趣
标签: laravel laravel-5.6
这适用于 laravel 5.2,但在 5.6 中我没有访问方法和方法获取,没有重定向。
【问题讨论】:
标签: laravel laravel-5.6
对于回调,https://laracasts.com/discuss/channels/testing/testing-socialite 有一个很好的示例,它指向 How to Test Laravel Socialite。
对于重定向位,我使用了以下函数
protected function guest_users_can_try_to_login_with_social_platform_login(string $provider)
{
$providerMock = \Mockery::mock('Laravel\Socialite\Contracts\Provider');
$providerMock->shouldReceive('redirect')->andReturn(new RedirectResponse($this->socialLoginRedirects[$provider]));
Socialite::shouldReceive('driver')->with($provider)->andReturn($providerMock);
//Check that the user is redirected to the Social Platform Login Page
$loginResponse = $this->call('GET', route('social-login', ['provider' => $provider]));
$loginResponse->assertStatus(302);
$redirectLocation = $loginResponse->headers->get('Location');
$this->assertContains(
$this->socialLoginRedirects[$provider],
$redirectLocation,
sprintf(
'The Social Login Redirect does not match the expected value for the provider %s. Expected to contain %s but got %s',
$provider,
$this->socialLoginRedirects[$provider],
$redirectLocation
)
);
}
$this->socialLognRedirects 在 setUp 函数中定义为
$this->socialLoginRedirects = [
'facebook' => 'https://www.facebook.com/v3.0/dialog/oauth',
'google' => 'https://accounts.google.com/o/oauth2/auth',
'github' => 'https://github.com/login/oauth/authorize',
'twitter' => 'https://api.twitter.com/oauth/authenticate'
];
这是使用的两条路线
Route::get('login/{provider}', 'Auth\LoginController@redirectToProvider')->middleware('guest')->name('social-login');
Route::get('login/{provider}/callback', 'Auth\LoginController@handleProviderCallback')->middleware('guest')->name('social-login-callback');
有任何问题请告诉我。
【讨论】: