Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

javid020's avatar

Using Laravel 5.8 authentication with external JSON/JWT API

Hi,

I'm building a Laravel 5.8 application to be the front-end to an external API written in Go. I POST a user/pass to the API which then responds with either HTTP/200 and a JSON Token (JWT) or an HTTP/401 to signal the credentials are invalid.

I would like to use Laravel's built-in auth mechanism (or anything which makes this work really) to be able to create pages and routes only for logged in users. It seems a lot of work to reinvent the wheel.

Any idea how I go about doing that? I guess I need a custom auth driver but can't find much reliable information for that.

[TLDR] Basically I need some code which checks if the API returns an HTTP/200, stores the token somewhere (session/cookie [but not database]) and then provide's some way to easily (virtually) log users into the Laravel app. That way I can create pages for logged in users only.

Thanks!

0 likes
4 replies
davorminchorov's avatar

You can use Guzzle for external API calls, and also modify the login() method in the LoginController to call the external API instead of using a database call (auth()->attempt()).

javid020's avatar

I did it, however, I cannot use Auth:: methods. I do not want just store it in session. Also, I want to use guards for it. @ruffles

Please or to participate in this conversation.