andersson2's avatar

Socialite + Passport? Bad redirects?

Hi. My laravel project uses socialite, and if someone tries to load a page while not logged in they're redirected to the central login page/site, another laravel project, which is using passport. In the Authenticate middleware on the first site:

protected function redirectTo(Request $request): ?string { return $request->expectsJson() ? null : (new LoginController($request))->redirectToExternalAuthServer($request)->getTargetUrl(); }

..and LoginController contains this: public function redirectToExternalAuthServer(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse { // ... return Socialite::driver($driver)->redirect(); } (It is kind of patchwork right now, it's the first time I'm doing this and some code is from tutorials)

This kind of works, I'm redirected to /oauth/authorize on the login site, with a bunch of parameters in the query string. Initially I got an error here, the redirect_uri in the query string didn't match the redirect value of the passport client in oauth_clients table. After fixing it, I'm now forwarded from /oauth/authorize to /auth/login.

But /auth/login doesn't allow GET requests, only POST. How are these endpoints supposed to be used? /auth/login + POST sounds to me like the receiving end of a form with user credentials? (Which was/is the plan initially, send not logged in users to the central login page and then return them to the site they were trying to load)

The login page is currently a plain passport install. I'm probably missing something fundamental here, why am I forwarded to /auth/login, which doesn't seem to work? Is it possible to make Passport forward me to a login form instead, and then back to the original site after successfully logging in?

0 likes
0 replies

Please or to participate in this conversation.