Passport: UUID cannot accepted on passports user id

Created on 15 Dec 2016  路  5Comments  路  Source: laravel/passport

Hi,

I've an User model which has an not incremental primary key (it's based on uuid). I am trying to integrate it with passports OAuth server. Unfortunately, I am facing with the error below where I am trying to create a secret for any user:

Invalid text representation: 7 ERROR: invalid input syntax for integer: "d4d52a80-c212-4ab4-823b-c62c3b814c2e"

I am using an Postgresql as a database. Sure, I know.. I can ignore the migration files and change it manually from the db but it's might be a compatibility issue

Most helpful comment

@kaankilic You must change the user_id in oauth_access_tokens to uuid type, follow this steps:

Create one migration to alter the table oauth_access_tokens:
php artisan make:migration alter_table_oauth_access_tokens

Drop the collumn user_id and re-create as uuid type:

public function up()
{
    Schema::table('oauth_access_tokens', function (Blueprint $table) {
        $table->dropColumn('user_id');
    });
    Schema::table('oauth_access_tokens', function (Blueprint $table) {
        $table->uuid('user_id')->index()->nullable();
    });
}

All 5 comments

In the default Passport migrations, you have to set the user foreign key to 'uuid'.

@kaankilic You must change the user_id in oauth_access_tokens to uuid type, follow this steps:

Create one migration to alter the table oauth_access_tokens:
php artisan make:migration alter_table_oauth_access_tokens

Drop the collumn user_id and re-create as uuid type:

public function up()
{
    Schema::table('oauth_access_tokens', function (Blueprint $table) {
        $table->dropColumn('user_id');
    });
    Schema::table('oauth_access_tokens', function (Blueprint $table) {
        $table->uuid('user_id')->index()->nullable();
    });
}

Closing for lack of activity, hope you got the help you needed :)

In case someone else comes upon this - make sure you have $incrementing = false; in your User Model, otherwise the user_id won't save properly.

to me throws an error, because first execute this new migration, so not found the oauth_access_tokens table. someone help me, pls

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MarkVilludo picture MarkVilludo  路  3Comments

raksrivastava picture raksrivastava  路  3Comments

rudolfdobias picture rudolfdobias  路  3Comments

Patskimoto picture Patskimoto  路  3Comments

mehrancodes picture mehrancodes  路  3Comments