Laravel passport with custom login controller

Viewed 7008

As mention in laravel-passport the login controller is made from php artisan make:auth and in our router web.php would have Auth::routes();

Simple code in our client-site

Route::get('/redirect', function () {

    $query = http_build_query([
        'client_id' => 'client-id',
        'redirect_uri' => 'http://client-site/callback-responses-url',
        'response_type' => 'code',
        'scope' => ''
    ]);

    return redirect('http://server-site/oauth/authorize?'.$query);
});

If the user is not log in the http://server-site/oauth/authorize?'.$query would be redirect to http://server-site/login

In any case of it i would like to redirect the login controller to my custom login controller. Then after i done check the use if is true would be show view about authorization request agreement

Simply i have tried to check oauth/authorize and i didnt find any function or controller handle that link. And if given any chance again. I would to know, more about the laravel-passport how the oauth work, and so do i could make the custom authorization view too after the user has login

Any help would be so helpful thank you (:

2 Answers

You can use personal access token method

in there you write your custom authentication method and when a pass that custom auth, u generate an access token for the user

i.e public function myCustomLoginMethod(Request $req) {

  // your custom authentication here
 $user = User::where("email",$req->email);

 //test for password and like so
 if (! Hash::check($req->password, $user->password)) {
      // wrong password
      return response('Unauthorize', 401);
  }

 if ( $user->is_admin ) {
    //create a token for the user
    $token = $user->createToken('Token Name')->accessToken;
 }else {
    //handle else
 }

  return token

}

Related