29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Authentication 157<br />

.<br />

9 {<br />

10 /**<br />

11 * Redirect the user to the GitHub authentication page.<br />

12 *<br />

13 * @return Response<br />

14 */<br />

15 public function redirectToProvider()<br />

16 {<br />

17 return Socialite::driver('github')->redirect();<br />

18 }<br />

19<br />

20 /**<br />

21 * Obtain the user information from GitHub.<br />

22 *<br />

23 * @return Response<br />

24 */<br />

25 public function handleProviderCallback()<br />

26 {<br />

27 $user = Socialite::driver('github')->user();<br />

28<br />

29 // $user->token;<br />

30 }<br />

31 }<br />

The redirect method takes care of sending the user to the OAuth provider, while the user method<br />

will read the incoming request and retrieve the user’s information from the provider. Before<br />

redirecting the user, you may also set “scopes” on the request using the scope method. This method<br />

will overwrite all existing scopes:<br />

.<br />

1 return Socialite::driver('github')<br />

2 ->scopes(['scope1', 'scope2'])->redirect();<br />

Of course, you will need to define routes to your controller methods:<br />

.<br />

1 Route::get('auth/github', 'Auth\AuthController@redirectToProvider');<br />

2 Route::get('auth/github/callback', 'Auth\AuthController@handleProviderCallba\<br />

3 ck');

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!