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

boneill81's avatar

Custom Authentication with third party authentication API

Hi Guys, I'd appreciate it if someone could point me in the right direction on this one.

I have almost completed a largish app in Laravel. It's all working very well. As a last component I need to add authentication to the system.

In the app's predecessor which is not using Laravel the authentication works fine with the third party authentication API. The methods use CURL to log in and retrieve details.

I realise that I will need to create a custom Auth for this and have given most of yesterday evening googling and reading all I could find. The problem is the documentation on adding custom authentication is light compared to other functionality and I am a little unsure as to where and how to add my existing methods for validation to my custom Auth .

I don't need to worry about registering etc. right now, I can build that up later but at present I just want to authenticate users. However rather than just patching a middleware I would like to do it in a clean and elegant manner like everything else in the new project.

I am using Laravel 5.4 and have been using the links in the following answer and also the answer itself. But I stopped until I could get some clear info on this.

http://stackoverflow.com/questions/32243363/how-to-create-laravel-5-1-custom-authentication-driver

Thanks in advance, I appreciate the help.

0 likes
2 replies
martinbean's avatar
Level 80

@boneill81 As you say, you need to create a custom user provider: https://laravel.com/docs/master/authentication#adding-custom-user-providers

The docs touch on the steps you need to take:

  1. Create a class that implements the UserProvider contract.
  2. Extend Auth in a service provider with your new user provider.
  3. Add a key to the providers array in config/auth.php for your new provider.

You’ll then be able to reference that key in conjunction with the auth middleware, i.e.

Route::group(['middleware' => 'auth:your_key'], function () {
    //
});

Unfortunately, we can’t tell you what your implementation of the AuthProvider contract will look like as we don’t know how your API works. The implementation details are up to you.

1 like
boneill81's avatar

@martinbean Thanks for your reply and apologies about the latesness in getting back to you. I ended up implmenting passwordless authentication on the project similar to the Laracasts video on the topic and it works great.

All the best.

Please or to participate in this conversation.