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

Burano's avatar

How to make a custom Laravel Authentication Provider?

I'm currently working on a project that requires something a little bit different than the usual Laravel User/Auth setup that works out the box.

For the life of me I've tried searching for some information on this, but can't seem to find any 'to the point' information or any source that explains it in an easy to understand way (sadly this includes the Laravel documentation).

So for my specific project, I'm developing an app that works together with a forum (IPBoard), and essentially, I plan on linking things like purchases directly to the forum account of the user. (This might be a bit tricky but I've heard you can do some cross database relationships in certain ways.)

It would be incredibly nice to have this setup in a way that I can just do the usual Auth::user() and have it grab the user (Especially if this does become a cross database relationship as writing that code/query over and over will become very messy/tedious).

However, the issue is I cannot really find any information on how this works. I've tried searching all over and the closest thing I can find is the actual Laravel docs (https://laravel.com/docs/5.8/authentication#adding-custom-user-providers), and even that feels like it doesn't explain it too well.

Hopefully someone here can possibly explain it and give some good explanations!

Also, as a side-question, I stated I want to link items in a separate database to a user located inside a forum database. What would be the best approach to doing that? I've seen some ways to do cross-database relationships, but they all seem a bit hacky imo.

0 likes
3 replies
Chrizzmeister's avatar
Level 19

Not really sure what the adding-customer-user-providers does not explain? The point of your custom provider is that it has custom code related to your use-case?

  1. Add a custom service provider which links to your custom class
  2. change the default provider to your custom provider in auth.php or create a new one so you can switch between the two
  3. Make sure your custom class adheres to the UserProvider interface
  4. If you set this up you can use all the normal Auth:: methods, like Auth::user()

And a user-provider alone is probably not enough so also take a look at the custom guards: https://laravel.com/docs/5.8/authentication#adding-custom-guards

But when reading your post I think you actually just want to authenticate with an existing forum user, in that case, you probably want to use this: https://laravel.com/docs/5.8/socialite Take a look at the custom driver website https://socialiteproviders.netlify.com/, you can create your own custom driver for IP-board

IPBoard as a single-sign-on method which is probably what you need. Read the documentation and add your own socialite driver.https://invisioncommunity.com/services/sso/

1 like
Snapey's avatar

You have not said WHY the standard authentication does not work for you

Burano's avatar

Hey Chrizzmeister,

Thanks! Socialite was exactly what I was looking for. Can't believe I didn't find it while I was looking around. Will take a look at the IPB SSO method you linked as well.

Thanks a lot for the recommendations!

Please or to participate in this conversation.