Here is how I handle the login in my Laravel app:
public function authenticate(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required',
]);
if ($validator->passes()) {
$credentials = array(
'email' => $request->email,
'password' => hash('sha512', $request->password)
);
if (User::where($credentials)->exists()) {
$user = User::where($credentials)->first();
Auth::login($user, isset($request->remember));
return redirect()->back()->withInput($request);
} else {
return redirect()->route('login');
}
} else {
return redirect()->route('login', ['error' => $validator->errors()->first()]);
}
}
And here is how I initiate the Authorize method of Laravel Passport:
public function auth(Request $request)
{
$request->session()->put('state', $state = Str::random(40));
$query = http_build_query([
'client_id' => '3',
'redirect_uri' => 'http://127.0.0.1:8000/authorize/response',
'response_type' => 'code',
'scope' => '',
'state' => $state
]);
return redirect('http://127.0.0.1:9000/oauth/authorize?'.$query);
}
So basically when I run auth function and I am not logged in when I nabvigate to http://127.0.0.1:9000/oauth/authorize.... url I get redirected to the Login route of my app. That's fine I need to login to authorize the permission. So far so good.
The problem is that after I login successfully I don't get redirected back to http://127.0.0.1:9000/oauth/authorize... URL. Why?
How can I fix that so that after I login I get directly redirected back to the Authorization prompt?