@@ -6,30 +6,30 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CreateRevolutTokensTable extends Migration |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the migrations. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function up() |
|
| 15 | - { |
|
| 16 | - Schema::create(config('revolut.tokens.database.table_name'), function(Blueprint $table) { |
|
| 17 | - $table->bigIncrements('id'); |
|
| 18 | - $table->string('type'); |
|
| 19 | - $table->mediumText('value'); |
|
| 20 | - $table->boolean('is_encrypted')->default(false); |
|
| 21 | - $table->timestamp('expires_at')->nullable(); |
|
| 22 | - $table->timestamp('created_at')->useCurrent(); |
|
| 23 | - }); |
|
| 24 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the migrations. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function up() |
|
| 15 | + { |
|
| 16 | + Schema::create(config('revolut.tokens.database.table_name'), function(Blueprint $table) { |
|
| 17 | + $table->bigIncrements('id'); |
|
| 18 | + $table->string('type'); |
|
| 19 | + $table->mediumText('value'); |
|
| 20 | + $table->boolean('is_encrypted')->default(false); |
|
| 21 | + $table->timestamp('expires_at')->nullable(); |
|
| 22 | + $table->timestamp('created_at')->useCurrent(); |
|
| 23 | + }); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Reverse the migrations. |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function down() |
|
| 32 | - { |
|
| 33 | - Schema::dropIfExists(config('revolut.tokens.database.table_name')); |
|
| 34 | - } |
|
| 26 | + /** |
|
| 27 | + * Reverse the migrations. |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function down() |
|
| 32 | + { |
|
| 33 | + Schema::dropIfExists(config('revolut.tokens.database.table_name')); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -20,74 +20,74 @@ |
||
| 20 | 20 | |
| 21 | 21 | class RevolutServiceProvider extends ServiceProvider |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Register services. |
|
| 25 | - * |
|
| 26 | - * @return void |
|
| 27 | - */ |
|
| 28 | - public function register() |
|
| 29 | - { |
|
| 30 | - $this->app->bind(CacheTokenRepository::class, function() { |
|
| 31 | - return new CacheTokenRepository( |
|
| 32 | - resolve(CacheFactory::class), |
|
| 33 | - config('revolut.tokens.cache.driver') |
|
| 34 | - ); |
|
| 35 | - }); |
|
| 23 | + /** |
|
| 24 | + * Register services. |
|
| 25 | + * |
|
| 26 | + * @return void |
|
| 27 | + */ |
|
| 28 | + public function register() |
|
| 29 | + { |
|
| 30 | + $this->app->bind(CacheTokenRepository::class, function() { |
|
| 31 | + return new CacheTokenRepository( |
|
| 32 | + resolve(CacheFactory::class), |
|
| 33 | + config('revolut.tokens.cache.driver') |
|
| 34 | + ); |
|
| 35 | + }); |
|
| 36 | 36 | |
| 37 | - $this->app->bind(TokenRepository::class, function() { |
|
| 38 | - return config('revolut.tokens.store') === 'database' |
|
| 39 | - ? new DatabaseTokenRepository |
|
| 40 | - : resolve(CacheTokenRepository::class); |
|
| 41 | - }); |
|
| 37 | + $this->app->bind(TokenRepository::class, function() { |
|
| 38 | + return config('revolut.tokens.store') === 'database' |
|
| 39 | + ? new DatabaseTokenRepository |
|
| 40 | + : resolve(CacheTokenRepository::class); |
|
| 41 | + }); |
|
| 42 | 42 | |
| 43 | - $this->app->bind(MakesHttpRequests::class, GuzzleHttpClient::class); |
|
| 43 | + $this->app->bind(MakesHttpRequests::class, GuzzleHttpClient::class); |
|
| 44 | 44 | |
| 45 | - $this->app->bind(ClientAssertion::class, function() { |
|
| 46 | - return new ClientAssertion( |
|
| 47 | - config('revolut.client_id'), |
|
| 48 | - config('revolut.private_key'), |
|
| 49 | - config('revolut.redirect_uri') |
|
| 50 | - ); |
|
| 51 | - }); |
|
| 45 | + $this->app->bind(ClientAssertion::class, function() { |
|
| 46 | + return new ClientAssertion( |
|
| 47 | + config('revolut.client_id'), |
|
| 48 | + config('revolut.private_key'), |
|
| 49 | + config('revolut.redirect_uri') |
|
| 50 | + ); |
|
| 51 | + }); |
|
| 52 | 52 | |
| 53 | - $this->app->bind(AuthorizationCodeRequest::class, function() { |
|
| 54 | - return new AuthorizationCodeRequest( |
|
| 55 | - config('revolut.client_id'), |
|
| 56 | - config('revolut.redirect_uri'), |
|
| 57 | - config('revolut.sandbox') |
|
| 58 | - ); |
|
| 59 | - }); |
|
| 53 | + $this->app->bind(AuthorizationCodeRequest::class, function() { |
|
| 54 | + return new AuthorizationCodeRequest( |
|
| 55 | + config('revolut.client_id'), |
|
| 56 | + config('revolut.redirect_uri'), |
|
| 57 | + config('revolut.sandbox') |
|
| 58 | + ); |
|
| 59 | + }); |
|
| 60 | 60 | |
| 61 | - $this->app->singleton('revolut', function() { |
|
| 62 | - return resolve(Client::class); |
|
| 63 | - }); |
|
| 64 | - } |
|
| 61 | + $this->app->singleton('revolut', function() { |
|
| 62 | + return resolve(Client::class); |
|
| 63 | + }); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Bootstrap services. |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function boot() |
|
| 72 | - { |
|
| 73 | - $this->publishes([ |
|
| 74 | - __DIR__ . '/../config/revolut.php' => config_path('revolut.php') |
|
| 75 | - ]); |
|
| 66 | + /** |
|
| 67 | + * Bootstrap services. |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function boot() |
|
| 72 | + { |
|
| 73 | + $this->publishes([ |
|
| 74 | + __DIR__ . '/../config/revolut.php' => config_path('revolut.php') |
|
| 75 | + ]); |
|
| 76 | 76 | |
| 77 | - if (config('revolut.tokens.store') === 'database') { |
|
| 78 | - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
|
| 79 | - } |
|
| 77 | + if (config('revolut.tokens.store') === 'database') { |
|
| 78 | + $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); |
|
| 81 | + $this->loadRoutesFrom(__DIR__ . '/../routes/web.php'); |
|
| 82 | 82 | |
| 83 | - if ($this->app->runningInConsole()) { |
|
| 84 | - $this->commands([ |
|
| 85 | - JWTCommand::class, |
|
| 86 | - CleanupCommand::class, |
|
| 87 | - ResetCommand::class, |
|
| 88 | - AuthorizeCommand::class, |
|
| 89 | - AccessTokenCommand::class, |
|
| 90 | - ]); |
|
| 91 | - } |
|
| 92 | - } |
|
| 83 | + if ($this->app->runningInConsole()) { |
|
| 84 | + $this->commands([ |
|
| 85 | + JWTCommand::class, |
|
| 86 | + CleanupCommand::class, |
|
| 87 | + ResetCommand::class, |
|
| 88 | + AuthorizeCommand::class, |
|
| 89 | + AccessTokenCommand::class, |
|
| 90 | + ]); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -8,35 +8,35 @@ |
||
| 8 | 8 | |
| 9 | 9 | class AccessTokenCommand extends Command |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * The name and signature of the console command. |
|
| 13 | - * |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $signature = 'revolut:access-token'; |
|
| 11 | + /** |
|
| 12 | + * The name and signature of the console command. |
|
| 13 | + * |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $signature = 'revolut:access-token'; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The console command description. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $description = 'Get an active revolut access token.'; |
|
| 18 | + /** |
|
| 19 | + * The console command description. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $description = 'Get an active revolut access token.'; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Execute the console command. |
|
| 27 | - * |
|
| 28 | - * @return mixed |
|
| 29 | - */ |
|
| 30 | - public function handle(TokenManager $manager) |
|
| 31 | - { |
|
| 32 | - try { |
|
| 33 | - $accessToken = $manager->getAccessToken(); |
|
| 34 | - } catch(AppUnauthorizedException $e) { |
|
| 35 | - $this->error('No valid refresh token found.'); |
|
| 36 | - $this->line("calling 'revolut:authorize' to re-authorize..."); |
|
| 37 | - return $this->call('revolut:authorize'); |
|
| 38 | - } |
|
| 25 | + /** |
|
| 26 | + * Execute the console command. |
|
| 27 | + * |
|
| 28 | + * @return mixed |
|
| 29 | + */ |
|
| 30 | + public function handle(TokenManager $manager) |
|
| 31 | + { |
|
| 32 | + try { |
|
| 33 | + $accessToken = $manager->getAccessToken(); |
|
| 34 | + } catch(AppUnauthorizedException $e) { |
|
| 35 | + $this->error('No valid refresh token found.'); |
|
| 36 | + $this->line("calling 'revolut:authorize' to re-authorize..."); |
|
| 37 | + return $this->call('revolut:authorize'); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - $this->info($accessToken->value); |
|
| 41 | - } |
|
| 40 | + $this->info($accessToken->value); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | { |
| 32 | 32 | try { |
| 33 | 33 | $accessToken = $manager->getAccessToken(); |
| 34 | - } catch(AppUnauthorizedException $e) { |
|
| 34 | + } catch (AppUnauthorizedException $e) { |
|
| 35 | 35 | $this->error('No valid refresh token found.'); |
| 36 | 36 | $this->line("calling 'revolut:authorize' to re-authorize..."); |
| 37 | 37 | return $this->call('revolut:authorize'); |
@@ -7,32 +7,32 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ResetCommand extends Command |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * The name and signature of the console command. |
|
| 12 | - * |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $signature = 'revolut:reset'; |
|
| 10 | + /** |
|
| 11 | + * The name and signature of the console command. |
|
| 12 | + * |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $signature = 'revolut:reset'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The console command description. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $description = 'Truncate the Revolut tokens table'; |
|
| 17 | + /** |
|
| 18 | + * The console command description. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $description = 'Truncate the Revolut tokens table'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Execute the console command. |
|
| 26 | - * |
|
| 27 | - * @return mixed |
|
| 28 | - */ |
|
| 29 | - public function handle() |
|
| 30 | - { |
|
| 31 | - $table = config('revolut.tokens.database.table_name'); |
|
| 24 | + /** |
|
| 25 | + * Execute the console command. |
|
| 26 | + * |
|
| 27 | + * @return mixed |
|
| 28 | + */ |
|
| 29 | + public function handle() |
|
| 30 | + { |
|
| 31 | + $table = config('revolut.tokens.database.table_name'); |
|
| 32 | 32 | |
| 33 | - if ($this->confirm('All Revolut tokens will be deleted permanently. Are you sure?')) { |
|
| 34 | - DB::table($table)->truncate(); |
|
| 35 | - $this->info($table . ' table has been truncated.'); |
|
| 36 | - } |
|
| 37 | - } |
|
| 33 | + if ($this->confirm('All Revolut tokens will be deleted permanently. Are you sure?')) { |
|
| 34 | + DB::table($table)->truncate(); |
|
| 35 | + $this->info($table . ' table has been truncated.'); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -16,95 +16,95 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | abstract class Token extends Model |
| 18 | 18 | { |
| 19 | - use Encryptable; |
|
| 19 | + use Encryptable; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Whether or not to use timestamps |
|
| 23 | - * |
|
| 24 | - * @var bool |
|
| 25 | - */ |
|
| 26 | - public $timestamps = false; |
|
| 21 | + /** |
|
| 22 | + * Whether or not to use timestamps |
|
| 23 | + * |
|
| 24 | + * @var bool |
|
| 25 | + */ |
|
| 26 | + public $timestamps = false; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * The attributes that are fillable |
|
| 30 | - * |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected $fillable = ['value']; |
|
| 28 | + /** |
|
| 29 | + * The attributes that are fillable |
|
| 30 | + * |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected $fillable = ['value']; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The attributes that should be cast to native types. |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $casts = [ |
|
| 41 | - 'is_encrypted' => 'boolean', |
|
| 42 | - 'expires_at' => 'datetime', |
|
| 43 | - 'created_at' => 'datetime', |
|
| 44 | - ]; |
|
| 35 | + /** |
|
| 36 | + * The attributes that should be cast to native types. |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $casts = [ |
|
| 41 | + 'is_encrypted' => 'boolean', |
|
| 42 | + 'expires_at' => 'datetime', |
|
| 43 | + 'created_at' => 'datetime', |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * The "booting" method of the model. |
|
| 48 | - * |
|
| 49 | - * @return void |
|
| 50 | - */ |
|
| 51 | - protected static function boot() |
|
| 52 | - { |
|
| 53 | - parent::boot(); |
|
| 46 | + /** |
|
| 47 | + * The "booting" method of the model. |
|
| 48 | + * |
|
| 49 | + * @return void |
|
| 50 | + */ |
|
| 51 | + protected static function boot() |
|
| 52 | + { |
|
| 53 | + parent::boot(); |
|
| 54 | 54 | |
| 55 | - static::creating(function($model) { |
|
| 56 | - $model->type = static::getType(); |
|
| 57 | - $model->expires_at = static::getExpiration(); |
|
| 58 | - }); |
|
| 55 | + static::creating(function($model) { |
|
| 56 | + $model->type = static::getType(); |
|
| 57 | + $model->expires_at = static::getExpiration(); |
|
| 58 | + }); |
|
| 59 | 59 | |
| 60 | - static::addGlobalScope('type', function(Builder $builder) { |
|
| 61 | - $builder->whereType(static::getType()); |
|
| 62 | - }); |
|
| 63 | - } |
|
| 60 | + static::addGlobalScope('type', function(Builder $builder) { |
|
| 61 | + $builder->whereType(static::getType()); |
|
| 62 | + }); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Get the name of the tokens table |
|
| 67 | - * |
|
| 68 | - * @return string |
|
| 69 | - */ |
|
| 70 | - public function getTable() |
|
| 71 | - { |
|
| 72 | - return config('revolut.tokens.database.table_name'); |
|
| 73 | - } |
|
| 65 | + /** |
|
| 66 | + * Get the name of the tokens table |
|
| 67 | + * |
|
| 68 | + * @return string |
|
| 69 | + */ |
|
| 70 | + public function getTable() |
|
| 71 | + { |
|
| 72 | + return config('revolut.tokens.database.table_name'); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Check if the token has expired |
|
| 77 | - * |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public function hasExpired() |
|
| 81 | - { |
|
| 82 | - return $this->expires_at ? $this->expires_at < now() : false; |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * Check if the token has expired |
|
| 77 | + * |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public function hasExpired() |
|
| 81 | + { |
|
| 82 | + return $this->expires_at ? $this->expires_at < now() : false; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Scope a query to only inlcude active tokens |
|
| 87 | - * |
|
| 88 | - * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 89 | - * @param bool $isActive |
|
| 90 | - * @return \Illuminate\Database\Eloquent\Builder |
|
| 91 | - */ |
|
| 92 | - public function scopeActive($query, bool $isActive = true) |
|
| 93 | - { |
|
| 94 | - $col = 'expires_at'; |
|
| 85 | + /** |
|
| 86 | + * Scope a query to only inlcude active tokens |
|
| 87 | + * |
|
| 88 | + * @param \Illuminate\Database\Eloquent\Builder $query |
|
| 89 | + * @param bool $isActive |
|
| 90 | + * @return \Illuminate\Database\Eloquent\Builder |
|
| 91 | + */ |
|
| 92 | + public function scopeActive($query, bool $isActive = true) |
|
| 93 | + { |
|
| 94 | + $col = 'expires_at'; |
|
| 95 | 95 | |
| 96 | - return $isActive |
|
| 97 | - ? $query->where($col, '>', now())->orWhereNull($col) |
|
| 98 | - : $query->where($col, '<=', now()); |
|
| 99 | - } |
|
| 96 | + return $isActive |
|
| 97 | + ? $query->where($col, '>', now())->orWhereNull($col) |
|
| 98 | + : $query->where($col, '<=', now()); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Delete all expired access tokens |
|
| 103 | - * |
|
| 104 | - * @return int The number of deleted tokens |
|
| 105 | - */ |
|
| 106 | - public static function clearExpired() |
|
| 107 | - { |
|
| 108 | - return (int) self::active(false)->delete(); |
|
| 109 | - } |
|
| 101 | + /** |
|
| 102 | + * Delete all expired access tokens |
|
| 103 | + * |
|
| 104 | + * @return int The number of deleted tokens |
|
| 105 | + */ |
|
| 106 | + public static function clearExpired() |
|
| 107 | + { |
|
| 108 | + return (int) self::active(false)->delete(); |
|
| 109 | + } |
|
| 110 | 110 | } |