Closed boldstar closed 5 years ago
company.multitenant-diy.test
one of the tenants?@fletch3555
Is company.multitenant-diy.test one of the tenants?
Yes
Any other customizations to the base laravel and/or hyn install?
No customizations
Any 3rd-party packages?
I have barryvdh for the cors issue
Using laravel/passport for api authentication, which is acutally what I am attempting work with on my login method
What's your route definition look like?
Route::group(['middleware' => 'tenancy.enforce'], function () {
Route::post('/login', 'PassportTokenController@login');
});
So Just to update though, with everything that I have shown after adding this
$env = app(Environment::class);
if ($fqdn = optional($env->hostname())->fqdn) {
config(['database.default' => 'tenant']);
}
it forced the guzzlehttp to query the tenant database, I got the method from yalls documentation however I am curious as to what I should be concerned with by doing it this way. Also this is the middleware I am using that is wrapping the login route
class EnforceTenancy
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
Config::set('database.default', 'tenant');
return $next($request);
}
}
Can you post the auth.php
part about guards.api
which should mention driver
passport
? You can add another key next to provider
and driver
called connection
with value tenant
(from the top of my head).
@luceos , thank you for the response and sorry for my late reply. I will add the extra key/value to the auth api guard and see what happens! Like I said though it is working with forcing the connection in the AppServiceProvider
file.
The problem is that $passport = DB::table('oauth_clients')->where('id', 2)->first();
the DB facade by default uses default db connection. That's why it queries on your main database.
You would have to specify the connection like
$passport = DB::connection('your_tenant_connection')->table('oauth_clients')->where('id', 2)->first();
@boldstar As someone that has used Passport a lot, I recommend you overwriting the default model, make them tenant aware and work using the models, not the DB:: the facade. As far as I remember all direct DB references in Passport were removed and you should be able to extend all models.
$env = app(Environment::class);
if ($fqdn = optional($env->hostname())->fqdn) {
config(['database.default' => 'tenant']);
}
please where did you place this ?
Description
Query tenant database while using GuzzleHttp\Client method
Actual behavior
Instead of querying the tenant database, it is checking the systems database
Expected behavior
I would expect that since the request has been wrapped in middleware, it would query my tenant database instead of the system database, because when I do my own query outside of the Guzzlehttp attempt I get the correct results.
Im not sure if there is something I am missing in configuration??
Here is the full method I am attempting to use
This is the error I get after making the attemp
I get the correct results at
$passport
and$hostname
so how do I make the guzzlehttp check the tenant database?Information
tenancy.php config
webserver.php config
Error log