Passport redirecting for authorization redirects to login route

Published 3 months ago by tuytoosh

Hi all, I want to use Passport for API authentication and I am going with laravel passport documentation, in requesting tokens, we need to redirect client to app for authorization, when I send get request for redirect, laravel redirects me to login route...

why?

bobbybouwmann

Well I need more context to help you further. Can you show some code?

tuytoosh

@bobbybouwmann Thank you for answer, This is my route for redirecting for authorization and it returns me to login route :(

Route::get('/redirect', function () {
    $query = http_build_query([
        'client_id' => '1',
        'redirect_uri' => 'http://127.0.0.1:8000/something_else',
        'response_type' => 'code',
        'scope' => '',
    ]);

    return redirect('http://127.0.0.1:8000/oauth/authorize?'.$query);
});
bobbybouwmann

Well your code is correct, but the problem is with the redirect_uri. It should not redirect to your localhost, but rather to an external url.

Currently you're building the oauth server. When someone tries to get access you need to redirect back to their application. That is the redirect_uri. In the example in the documentation they use the example.com domain to show you that this are two different applications.

The reason that you get redirected to the login screen is because /something_else probably needs some authentication, but the authentication is never handled there. So you can use the same url, but then you need to handle the token you get back from the redirect_uri. So you need to reuse the token you get back.

tuytoosh

@bobbybouwmann I changed redirect_uri to example.com but still I have same problem...

bobbybouwmann

example.com should be a website that connects to your application. That can be your own domain or a third party domain

tuytoosh

@bobbybouwmann The problem is with oauth/authorize route... when I enter this route manually in address bar, it redirects me to login route again!

Please sign in or create an account to participate in this conversation.