rootinc / laravel-azure-middleware

94 stars 39 forks source link

Multi Domain Authentication #45

Closed francis-fullstack closed 3 years ago

francis-fullstack commented 3 years ago

Is it possible to authenticate different domain? I want to log in with different domain

francis-fullstack commented 3 years ago

I mean I want other tenant user to log in my current tenant, is that possible?

danieltjewett commented 3 years ago

I would solve this by having a separate login form, that only asks for the user's email. Assuming a successful find on the user object, there could be a join table of what domain they are apart of (or just put it on the user table). After the lookup, we could override the config variable for the tenant with the one on the user object we just looked up (e.g. Config::set('azure.tenant_id', $user->tenant->name)). From there, we could call the azure functionality like normal, even passing in the email address since we have this now.

    /**
     * Redirects to the Azure route.  Typically used to point a web route to this method.
     * For example: Route::get('/login/azure', '\RootInc\LaravelAzureMiddleware\Azure@azure');
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|mixed
     */
    public function azure(Request $request)
    {
        return redirect()->away( $this->getAzureUrl() . "&login_hint=" . $request->input('email') );
    }