Skip to content
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

Authenticated model without middleware not correct #132

Open
shoxrux1996 opened this issue Jun 24, 2020 · 0 comments
Open

Authenticated model without middleware not correct #132

shoxrux1996 opened this issue Jun 24, 2020 · 0 comments

Comments

@shoxrux1996
Copy link

shoxrux1996 commented Jun 24, 2020

I need to get authenticated user without middleware auth (because it should work for guests too)
I am sending Carrier token in header, but it returns authenticated users: Admin and Carrier

routes/api.php

Route::get('check/user', function (Request $request) {
    dd([
        'api' => $request->user('api'),
        'admin' => $request->user('admin'),
        'carrier' => $request->user('carrier'),
        'user' => Auth::user(),
    ]);
});

Response:
returns Admin and Carrier model

array:4 [▼
  "api" => null
  "admin" => App\Models\Admin {#923 ▶}
  "carrier" => App\Models\Carrier {#1048 ▶}
  "user" => null
]

in Kernel.php

protected $routeMiddleware = [
      'auth' => \SMartins\PassportMultiauth\Http\Middleware\MultiAuthenticate::class,
      'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
      'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
      'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
      'can' => \Illuminate\Auth\Middleware\Authorize::class,
      'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
      'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
      'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
      'oauth.providers' => \SMartins\PassportMultiauth\Http\Middleware\AddCustomProvider::class,
      ...
  ];

in config/auth.php

    'defaults' => [
        'guard' => 'web',
    ],
'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'passport',
            'provider' => 'users'
        ],
        'admin' => [
            'driver' => 'passport',
            'provider' => 'admins'
        ],
        'carrier' => [
            'driver' => 'passport',
            'provider' => 'carriers'
        ],
    ],
 'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Models\Admin::class,
        ],
        'carriers' => [
            'driver' => 'eloquent',
            'model' => App\Models\Carrier::class,
        ]
    ],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant