Framework: Authentication using custom guard

Created on 14 Sep 2017  路  8Comments  路  Source: laravel/framework

  • Laravel Version: 5.5.4
  • PHP Version: 7.1.7
  • Database Driver & Version: MySQL 5.7.19

Description:

Authentication attempt method not work, when using custom guard

Steps To Reproduce:

Auth::guard('api')->attempt($credentials)

will get error
Method attempt does not exist

Most helpful comment

Can you provide some more info on this? There doesn't appear to be any documentation. I thought token and passport drivers were completely different. If we want to perform manual authentication, as described in the authentication documentation, but with passport, how are we supposed to do it?
Thank you,

All 8 comments

Yes attempt() doesn't work with token guards, only Guards that implement StatefulGuard

Can you provide some more info on this? There doesn't appear to be any documentation. I thought token and passport drivers were completely different. If we want to perform manual authentication, as described in the authentication documentation, but with passport, how are we supposed to do it?
Thank you,

So what to do? Is there anyway to attempt user, without creating LoginProxy, and finding user manually??

+1

any one?? no solution? where is the so called big laravel community?

where is the so called big laravel community?

Not everyone doing what the poster attempting to do. api guard was design to just verify api_key and api_token. There's no concept of attempting to login for this guard.

You might want to consider OAuth2 (check Laravel Passport) or JWT which you need to login using user credential to get an access token.

Not everyone doing what the poster attempting to do

yeah, sure, so that people above is who?

Answer to people :
You need to authorize user manually. Override authorize function so that would find the user by token and then authorize user with Auth::setUser($token->user); etc. That was our workaround with oauth2 authorization. Also u need to override register and all auth functions as well. It's pity that such great framework and such popular package as passport have no connection "out of box" in this case...

It's best to use the community channels if you want help from the community. This repo is for bug reporting and pull requests.
Laracasts Forum
Larachat Slack
Laravel.IO
There's also a Laravel gitter channel

All of these links will take you to a very active community of Laravel developers.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamborJan picture JamborJan  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

YannPl picture YannPl  路  3Comments

felixsanz picture felixsanz  路  3Comments

progmars picture progmars  路  3Comments