In my Laravel-5.8 I am using Azure Socialite Login.
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/dashboard';
protected $username = 'username';
public function redirectToProvider()
{
return Socialite::with('azure')->redirect();
}
public function handleProviderCallback()
{
$azureUser = Socialite::with('azure')->user();
try
{
$user = User::where('email', $azureUser->email)->orWhere('username', $azureUser->user['mailNickname'])->first();
if($user)
{
if(Auth::loginUsingId($user->id))
{
$user->update([
'last_login_at' => now(),
]);
return redirect()->intended('/dashboard');
}
}
}
catch(\Exception $e)
{
session()->flash("error", "Authentication failed, kindly contact the Administrator!");
return redirect(route('login'));
}
}
}
'azure' => [
'client_id' => env('AZURE_KEY','mykey'),
'client_secret' => env('AZURE_SECRET','myazuresecret'),
'redirect' => env('AZURE_REDIRECT_URI','https://myapp/login/azure/callback')
],
This is working and it uses: https://myapp.com
But I'm now asked to make it multi-company application using single DB. There is a company table and each table have company_id
Each having this url:
https://myapp.com
https://company1.myapp.com
https://company2.myapp.com
I now have these tables:
class Company extends Model
{
protected $table = 'companies';
protected $fillable = [
'id',
'company_name',
'subdomain',
];
}
From the company table, where subdomain is null then it is https://myapp.com , while subdomain field could be company1 or company2 and so on.
class User extends Authenticatable
{
protected $fillable = [
'name',
'email',
'company_id',
'password',
];
}
The question is on the azure url redirect:
'redirect' => env('AZURE_REDIRECT_URI','https://myapp/login/azure/callback')
since it is redirecting to the main domain myapp.
What effect will this have on company1.myapp.com and company2.myapp?
How do I make it redirect to the subdomains also?
Thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community