Created
May 1, 2018 18:13
-
-
Save akvsh-r/22af4390bc97716a17cc4328b55e403e to your computer and use it in GitHub Desktop.
Laravel Passport API Login after registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Illuminate\Foundation\Auth; | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Auth\Events\Registered; | |
trait RegistersUsers | |
{ | |
use RedirectsUsers; | |
/** | |
* Show the application registration form. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function showRegistrationForm() | |
{ | |
return view('auth.register'); | |
} | |
/** | |
* Handle a registration request for the application. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return \Illuminate\Http\Response | |
*/ | |
public function register(Request $request) | |
{ | |
$this->validator($request->all())->validate(); | |
event(new Registered($user = $this->create($request->all()))); | |
$data = $request->only('email','name','password'); | |
$client = \Laravel\Passport\Client::find( 4)->first(); | |
$request->request->add([ | |
'grant_type' => 'password', | |
'client_id' => $client->id, | |
'client_secret' => $client->secret, | |
'username' => $data['email'], | |
'password' => $data['password'], | |
'scope' => null, | |
]); | |
// Fire off the internal request. | |
$proxy = Request::create( | |
'oauth/token', | |
'POST' | |
); | |
return \Route::dispatch($proxy); | |
$this->guard()->login($user); | |
return $this->registered($request, $user) | |
?: redirect($this->redirectPath()); | |
} | |
/** | |
* Get the guard to be used during registration. | |
* | |
* @return \Illuminate\Contracts\Auth\StatefulGuard | |
*/ | |
protected function guard() | |
{ | |
return Auth::guard(); | |
} | |
/** | |
* The user has been registered. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param mixed $user | |
* @return mixed | |
*/ | |
protected function registered(Request $request, $user) | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment