250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Android
- ubuntu
- Passport
- 구글 API
- Vue
- 해시키
- PostgreSQL
- FCM
- OAuth
- https
- mac
- 파이썬
- MacOS
- window
- Prometheus
- AWS
- MYSQL
- node
- python
- alb
- selenium
- Laravel
- 안드로이드
- pip
- php
- Cordova
- nginx
- SSH
- flutter
- Vue.js
Archives
- Today
- Total
print( sjw.iq == 200) output : true
[Laravel] laravel Passport oauth uuid 사용하기 본문
728x90
반응형
Passport 관련 테이블을 int 가 아닌 uuid를 사용하는 방법에 대해서 포스팅하겠습니다.
해당 명령어를 통해 vendor 에 있는 oauth 관련 migration 들을 /app/database/migrations에 가져올 수 있습니다.
php artisan vendor:publish --tag=passport-migrations 를 사용하여 기본 마이그레이션을 가져올 수 있습니다.
[oauth_auth_codes] - table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthAuthCodesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_auth_codes', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->bigInteger('user_id');
$table->uuid('client_id');
$table->text('scopes')->nullable();
$table->boolean('revoked');
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('oauth_auth_codes');
}
}
[oauth_access_tokens] - table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthAccessTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_access_tokens', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->bigInteger('user_id')->index()->nullable();
$table->uuid('client_id');
$table->string('name')->nullable();
$table->text('scopes')->nullable();
$table->boolean('revoked');
$table->timestamps();
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('oauth_access_tokens');
}
}
[oauth_refresh_tokens] - table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthRefreshTokensTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_refresh_tokens', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->string('access_token_id', 100)->index();
$table->boolean('revoked');
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('oauth_refresh_tokens');
}
}
[oauth_clients] - table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthClientsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_clients', function (Blueprint $table) {
$table->uuid('id');
$table->primary('id');
$table->bigInteger('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');
}
}
[oauth_personal_access_clients] - table
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthPersonalAccessClientsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('oauth_personal_access_clients', function (Blueprint $table) {
$table->increments('id');
$table->uuid('client_id')->index();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('oauth_personal_access_clients');
}
}
/database/migrations/ 밑에 해당 테이블들의 코드를 추가하거나 바꿔 주세요!
그리고 /app/providers/AuthServiceProvider.php 파일에서
boot 메소드에 아래 코드를 추가해주세요~!
/* passport table id uuid*/
Client::creating(function (Client $client) {
$client->incrementing = false;
$client->id = \Ramsey\Uuid\Uuid::uuid4()->toString();
});
Client::retrieved(function (Client $client) {
$client->incrementing = false;
});
그러면 기본 passport는 int로 키값을 지정하는데 uuid로 키값을 지정할 수 있습니다~!
감사합니다.
728x90
반응형
'PHP' 카테고리의 다른 글
[PHP]POST max upload size 조정 (0) | 2020.08.12 |
---|---|
[MacOS + Apache + PHP] 설정하기 (0) | 2020.07.27 |
[Laravel] Laravel Scheduler (0) | 2020.03.18 |
[Laravel] Laravel에서 Swagger 사용하기! (0) | 2020.03.13 |
[Laravel] Passport를 이용한 client_id, client_secret 발급하기(oauth) (0) | 2020.02.13 |
Comments