Reputation: 8378
I am having difficulty setting up Passport in Laravel 5.6. The first time when I followed this tutorial, I had implemented perfectly but now again when I am following than getting following error.
{
"error": "invalid_credentials",
"message": "The user credentials were incorrect."
}
I have tried out all possible solutions but none of them works. So thought to post it here.
Info: I am using
iMac
-High Sierra
.storage
directory has777
permission. I have set usingsudo chmod -R 777 storage
command. However, when I checked thelaravel.log
file didn't have permission so I have grant777
to it as well. still getting the error.
local.ERROR: The user credentials were incorrect. {"exception":"[object] (League\\OAuth2\\Server\\Exception\\OAuthServerException(code: 6): The user credentials were incorrect. at /Users/username/Sites/mysite/vendor/league/oauth2-server/src/Exception/OAuthServerException.php:160)
composer require laravel/passport
app.php
Laravel\Passport\PassportServiceProvider::class,
php artisan migrate
Passport::routes()
use
HasApiTokens
to User
modelauth.php
set gourds
api
driver
to password
php artisan passport:client --passoword
php artisan passport:keys
Route::post( 'register', 'Api\Auth\RegisterController@register' );
namespace App\Http\Controllers\Api\Auth;
use App\User;
use function bcrypt;
use function dd;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Route;
use Laravel\Passport\Client;
use function response;
class RegisterController extends Controller
{
private $client;
public function __construct() {
$this->client = Client::findOrFail(1);
}
public function register( Request $request ) {
$this->validate( $request, [
'name' => 'required',
'email' => 'required|email|unique:users,email',
'password' => 'required|min:6|confirmed',
] );
$user = User::create( [
'name' => request( 'name' ),
'email' => request( 'email' ),
'password' => bcrypt( 'password' )
] );
$params = [
'grant_type' => 'password',
'client_id' => $this->client->id,
'client_secret' => $this->client->secret,
'username' => request( 'email' ),
'password' => request( 'password' ),
'scope' => '*'
];
$request->request->add( $params );
$proxy = Request::create( 'oauth/token', 'POST' );
return Route::dispatch( $proxy );
}
}
Upvotes: 1
Views: 2001
Reputation: 664
You are hashing the word 'password' not the actual password coming from request.
You should use it like this:
bcrypt(request('password'))
Upvotes: 1
Reputation: 45
try to use hash::make function instead of bcrypt for your password when creating user like below
$user = User::create([
'name' => request('name'),
'email' => request('email'),
'password' => Hash::make(request('password'))
]);
Upvotes: 0