dimanche 9 juin 2019

Laravel test Passport::actingAs($user) use routes?

I have custom passport user login validation (i made it following this) so i make my custom /oauth/token with this route:

/routes/auth.php

Route::post('/oauth/token', [
    'uses' => 'Auth\CustomAccessTokenController@issueUserToken'
]);

/app/controllers/auth/CustomAccessTokenController.php

namespace App\Http\Controllers\Auth;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Psr\Http\Message\ServerRequestInterface;

class CustomAccessTokenController extends Controller
{
    public function issueUserToken(ServerRequestInterface $request)
    {
        $httpRequest = request();

        if ($httpRequest->grant_type == 'password') {
            $user = User::where('email', $httpRequest->username)->first();
            return $this->issueToken($request);
        }
    }
}

If i make a manual POST request to domain.com/oauth/token is correctly handled by the custom controller but when i use Passport::actingAs($user); in a phpunit test not. This Passport::actingAs(); use the routes or have other way to get the authentication token?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2WnR6xz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire