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

Auth Controller Help #1

Open
AugmentBLU opened this issue Nov 16, 2017 · 0 comments
Open

Auth Controller Help #1

AugmentBLU opened this issue Nov 16, 2017 · 0 comments

Comments

@AugmentBLU
Copy link

Thanks for attempting to get Passport working with OC!

I have attempted to get this working but having an issue with working on an Auth Controller.

The BackendUser::attempt is not a recognised function, here is the controller which is being used with my Routes.

Routes

Route::group(['prefix' => 'api'], function(){
    Route::post('login', 'LukeTowers\Passport\Http\Controllers\API\PassportController@login');
});

Controller

use Request;
use Backend\Classes\Controller;
use LukeTowers\Passport\Models\BackendUser;

class PassportController extends Controller
{
    public $successStatus = 200;

    public function login(){

        if(BackendUser::attempt(['login' => request('login'), 'password' => request('password')])){
            $user = BackendUser::user();

            $success['token'] =  $user->createToken('MyApp')->accessToken;

            return response()->json(['success' => $success], $this->successStatus);
        }
        else{
            return response()->json(['error'=>'Unauthorised'], 401);
        }
    }
}

If I change the Backend User model that you included to extend \BackendAuth instead, and change the login controller function to use BackendUser::authenticate

change $user = BackendUser::user(); to $user = BackendUser::getUser(); it will return an object but it will fail at the $user->createToken('MyApp')->accessToken step.

Any idea if this is directly related to the Passport plugin attempt or a deeper issue with the OC Auth implementation?

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