statamic / ideas

đŸ’¡Discussions on ideas and feature requests for Statamic
https://statamic.dev
31 stars 1 forks source link

Make it possible to use tenant id with socialite and Microsoft Graph #432

Open Anders-HM opened 4 years ago

Anders-HM commented 4 years ago

I'm currently using Oauth/Socialite for authentication with the Microsoft Graph provider and it works beautifully. The only thing I can't get to work is using a single tenant instead of using the "common" setting, which requires using a multi tenancy setting in Microsoft Graph. Using a single tenant is required to limit logins to only those in our Office365 domain, which is a design requirement.

In the Socialite provider documentation there is a section on setting the tenant id, it requires the following code:

return Socialite::with('graph')->setTenantId('a-microsoft-tenant-id')->redirect();

But there is no way of using this code in Statamic's settings files. I did find a workaround, which was to edit a file called Oauthcontroller in the vendor folder, using the code above, but that doesn't seem like a very good solution.

jasonvarga commented 4 years ago

Try this:

In your app/Providers/AppServiceProvider.php's boot method, add:

public function boot()
{
    \Laravel\Socialite\Facades\Socialite::with('graph')->setTenantId('a-microsoft-tenant-id');
}
Anders-HM commented 4 years ago

I get the following error message.

InvalidArgumentException Driver [graph] not supported.

jasonvarga commented 4 years ago

What does your config/statamic/oauth.php file look like?

Anders-HM commented 4 years ago
<?php

return [

    'enabled' => env('STATAMIC_OAUTH_ENABLED', false),

    'providers' => [
        'graph' => 'Office365',
    ],

    'routes' => [
        'login' => 'oauth/{provider}',
        'callback' => 'oauth/{provider}/callback'
    ],

];
jasonvarga commented 4 years ago

Ah it works a bit differently than I thought. Okay, we'll need to add a nice way for you to hook in where necessary.

Anders-HM commented 4 years ago

Sounds good, thank you for the quick reply!

github-actions[bot] commented 3 years ago

This issue has not had recent activity and has been marked as stale — by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me.

Anders-HM commented 3 years ago

This is still a feature I would like to have in Statamic