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

noblemfd's avatar

How to socialite in a multi-company application

In my Laravel-5.8 project, I am developing a multi-company application. Each company have its own Socialite for login. For instance, one company can use azure, another can use facebook or azure. Each company will have it's socialite ids.

config/service for socialite can look like this:

'facebook' => [
     'client_id' => '2091838484373383',         // Your facebook Client ID
    'client_secret' => 'bc6b19e476123f0f6bc55549b6e36d36', // Your facebook Client Secret
    'redirect' => 'http://localhost:8888/login/facebook/callback',
],    

'azure' => [
    'client_id' => env('AZURE_KEY','ffrrdd'),
    'client_secret' => env('AZURE_SECRET','ffgh'),
    'redirect' => env('AZURE_REDIRECT_URI','https://company1/login/azure/callback')
],

As I explained, two companies can have azure but with difference IDs

I have these tables:

class OrgCompany extends Model
{
    protected $table = 'org_companies';
    protected $primaryKey = 'id';
    protected $fillable = [
                'id',
                'organization_name',
                'email',
            ];
}


class User extends Authenticatable
{
    use Notifiable;

    protected $fillable = [
        'name', 
        'email', 
        'email_verified_at',
        'company_id',
        'password', 
        'updated_at',
        'created_at',
    ];
}

Each users have company_id.

How do I dynamically configure and develop the application, that when a users tries to login, it checks the company_id and use the socialite for that company?

Note: I am using a single database with company_id in the tables

Thanks

0 likes
3 replies
martinbean's avatar

@noblemfd You’ll need to let each company set the client ID/secret/redirect URIs for each service (Azure, Facebook, etc). You’ll then need some way of identifying which company a user is trying to log in for up front so you can pull those credentials from the database and use the correct client ID, secret, and redirect URIs.

Please or to participate in this conversation.