I am getting error "Class 'App\Http\Controllers\AccessTokenController' not found"
kobidkunda opened this issue · 4 comments
I copied with exact same code you provided
and prying post with postman
{ "grant_type" : "password", "client_id" : "2", "client_secret": "l7cKMZN5IXuYB2AnG6HchlrnPtUgg2O4LM1AW3ty", "username": "l@l.com", "password": "l@l.com" }
i am getting error "Class 'App\Http\Controllers\AccessTokenController' not found"
Is this AccessTokenController
existing in app/Http/Controllers
folder? and you have not changed your namespace?
This is my Controller
`<?php
namespace App\Http\Controllers\Auth;
use App\Customer;
use Illuminate\Database\ModelNotFoundException;
use Laravel\Passport\Http\Controllers\AccessTokenController;
use Laravel\Passport\TokenRepository;
use League\OAuth2\Server\AuthorizationServer;
use Psr\Http\Message\ServerRequestInterface;
use Lcobucci\JWT\Parser as JwtParser;
class CustomerTokenAuthController extends AccessTokenController
{
/**
* The authorization server.
*
* @var \League\OAuth2\Server\AuthorizationServer
*/
protected $server;
/**
* The token repository instance.
*
* @var \Laravel\Passport\TokenRepository
*/
protected $tokens;
/**
* The JWT parser instance.
*
* @var \Lcobucci\JWT\Parser
*/
protected $jwt;
/**
* Create a new controller instance.
*
* @param \League\OAuth2\Server\AuthorizationServer $server
* @param \Laravel\Passport\TokenRepository $tokens
* @param \Lcobucci\JWT\Parser $jwt
*/
public function __construct(AuthorizationServer $server,
TokenRepository $tokens,
JwtParser $jwt)
{
parent::__construct($server, $tokens, $jwt);
}
/**
* Override the default Laravel Passport token generation
*
* @param ServerRequestInterface $request
* @return array
* @throws UserNotFoundException
*/
public function issueToken(ServerRequestInterface $request)
{
$body = (parent::issueToken($request));
$token = json_decode($body, true);
if (array_key_exists('error', $token)) {
return response()->json([
'error' => $token['error'],
'status_code' => 401
], 401);
}
$data = $request->getParsedBody();
$email = $data['username'];
switch ($data['provider']) {
case 'customers';
try {
$user = Customer::where('email', $email)->firstOrFail();
} catch (ModelNotFoundException $e) {
return response()->json([
'error' => $e->getMessage(),
'status_code' => 401
], 401);
}
break;
default :
try {
$user = User::where('email', $email)->firstOrFail();
} catch (ModelNotFoundException $e) {
return response()->json([
'error' => $e->getMessage(),
'status_code' => 401
], 401);
}
}
return compact('token', 'user');
}
}`
my my error
This is in the Auth
namespace. App\Http\Controllers\Auth
look!
You should have App\Http\Controllers\Auth\AccessTokenController
instead of App\Http\Controllers\AccessTokenController
only.
Yes Thanks a Lot @jsdecena