-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authorization only works if user authenticated with 'web' guard #294
Comments
Don't think this has to do with the package. Can you post your |
Here is my gate function. virag@myapp.com which uses 'web' guard and dev@myapp.com uses 'admin' guard. |
This has nothing to do with Telescope. You're always free to override the |
Telescope uses
|
I am struggling to get this working, sorry to bother you! In my
In the authorization method, if I |
I had the same issue, the gate resolves the user with the default guard even when passing |
@kiwina Your solution worked for me. Thanks! Edit: I was wrong. It killed the authentication on non-default guards. |
@kiwina I can confirm that changing guard using the following code in TelescopeServiceProvider works:
|
in my case , the auth()->setDefaultDriver('admin') method broken my api authorization.
ps: the Admin::user() function is in laravel-admin package |
Yet another solution for the authenticate override… I just looped over all the defined guards and checked each one individually instead of locking telescope down to one specific guard: protected function authorization()
{
$this->gate();
Telescope::auth(function ($request) {
$result = collect(config('auth.guards'))->keys()->reduce(function($auth, $guard) use ($request) {
if ($auth) {
return $auth;
}
app('auth')->shouldUse($guard);
return Gate::check('viewTelescope', [$request->user()]);
}, app()->environment('local'));
app('auth')->shouldUse(config('auth.defaults.guard'));
return $result;
});
} |
Why not just protected function gate()
{
Gate::define('viewTelescope', function() {
return auth("admin")->user()->isAdmin();
});
} where |
With multiple guards, this solution worked for me. Thanks @matthillman |
Here's what I do in my code. protected function authorization()
{
// Always set `Auth::shouldUse('YOUR_GUARD')` before calling Gate methods like allow, denies, define, check, etc.
// Link: https://github.com/laravel/framework/issues/13788#issuecomment-249550532
Auth::shouldUse('YOUR_GUARD');
$this->gate();
Telescope::auth(function ($request) {
return Gate::check('viewTelescope', [$request->user('YOUR_GUARD')]);
});
}
/**
* Register the Telescope gate.
*
* This gate determines who can access Telescope in non-local environments.
*
* @return void
*/
protected function gate()
{
Gate::define('viewTelescope', function ($user) {
// Just in case if you want to make sure if there's a user. Store that data in laravel.log to check later.
Log::info($user);
return in_array($user->email, [
'yourmail@mail.com'
]);
});
} Hope it helps for everyone include my self! |
all my guards are api base and I use passport. after overwrite authorization method, how can I set a valid berear token to access telescope panel? ``
|
It's work for me. Thanks bro |
I am using multiple guard in my application.
For production use of Telescope, If i allow any user belongs to web guards so it works fine. But if I logged in with 'admin' guard than user not authenticated for telescope access. I have already defined user emails in service provider gate method.
Originally posted by @shahvirag07 in https://github.com/laravel/telescope/issue_comments#issuecomment-434941088
The text was updated successfully, but these errors were encountered: