I am making a react app that uses a laravel passport backend to get and post data from a database. I have full control over the app code and the laravel backend code.
I can make an access token just fine, either using a client, or simply by issuing a user to make one, but I can't use this access token to access data, as described here. Sending such a request with the generated access token gives me a 401 every time.
I believe My problem is when making clients. I have 2 clients (made when running php artisan passport:install), but they both have user_id=null. I'm assuming this should be set some integer when a user uses the client to for example issue an access token? But, it doesn't.
So, does anyone have any idea of what I am doing wrong?
Below I am posting my user model, and the migration files users and oath_clients. Feel free to ask for more code if needed!
User model:
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'api_token', 'redcap_token', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
Users migration:
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('api_token', 60)->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
Oauth migrations
class CreateOauthClientsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_clients', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->index()->nullable();
$table->string('name');
$table->string('secret', 100);
$table->text('redirect');
$table->boolean('personal_access_client');
$table->boolean('password_client');
$table->boolean('revoked');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('oauth_clients');
}
}