@@ -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 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return [ |
4 | - /* |
|
4 | + /* |
|
5 | 5 | |-------------------------------------------------------------------------- |
6 | 6 | | API Access |
7 | 7 | |-------------------------------------------------------------------------- |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | | If this applies to your Business, set 'expire_api_access' to true. |
12 | 12 | | |
13 | 13 | */ |
14 | - 'expire_api_access' => true, |
|
14 | + 'expire_api_access' => true, |
|
15 | 15 | |
16 | - /* |
|
16 | + /* |
|
17 | 17 | |-------------------------------------------------------------------------- |
18 | 18 | | Environment |
19 | 19 | |-------------------------------------------------------------------------- |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | | Default is true. |
23 | 23 | | |
24 | 24 | */ |
25 | - 'sandbox' => env('REVOLUT_SANDBOX', true), |
|
25 | + 'sandbox' => env('REVOLUT_SANDBOX', true), |
|
26 | 26 | |
27 | - /* |
|
27 | + /* |
|
28 | 28 | |-------------------------------------------------------------------------- |
29 | 29 | | Private Key Path |
30 | 30 | |-------------------------------------------------------------------------- |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | | authorization process. |
35 | 35 | | |
36 | 36 | */ |
37 | - 'private_key' => env('REVOLUT_PRIVATE_KEY'), |
|
37 | + 'private_key' => env('REVOLUT_PRIVATE_KEY'), |
|
38 | 38 | |
39 | - /* |
|
39 | + /* |
|
40 | 40 | |-------------------------------------------------------------------------- |
41 | 41 | | Client ID |
42 | 42 | |-------------------------------------------------------------------------- |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | | selecting the relevant API certificate. |
47 | 47 | | |
48 | 48 | */ |
49 | - 'client_id' => env('REVOLUT_CLIENT_ID'), |
|
49 | + 'client_id' => env('REVOLUT_CLIENT_ID'), |
|
50 | 50 | |
51 | - /* |
|
51 | + /* |
|
52 | 52 | |-------------------------------------------------------------------------- |
53 | 53 | | Oauth Redirect URI |
54 | 54 | |-------------------------------------------------------------------------- |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | | necessary route and controllers. |
61 | 61 | | |
62 | 62 | */ |
63 | - 'redirect_uri' => env('REVOLUT_REDIRECT_URI'), |
|
63 | + 'redirect_uri' => env('REVOLUT_REDIRECT_URI'), |
|
64 | 64 | |
65 | - /* |
|
65 | + /* |
|
66 | 66 | |-------------------------------------------------------------------------- |
67 | 67 | | Tokens |
68 | 68 | |-------------------------------------------------------------------------- |
@@ -79,22 +79,22 @@ discard block |
||
79 | 79 | | Supported stores: 'database', 'cache' |
80 | 80 | | |
81 | 81 | */ |
82 | - 'tokens' => [ |
|
82 | + 'tokens' => [ |
|
83 | 83 | |
84 | - 'encrypt' => true, |
|
84 | + 'encrypt' => true, |
|
85 | 85 | |
86 | - 'store' => 'database', |
|
86 | + 'store' => 'database', |
|
87 | 87 | |
88 | - 'database' => [ |
|
89 | - 'table_name' => 'revolut_tokens' |
|
90 | - ], |
|
88 | + 'database' => [ |
|
89 | + 'table_name' => 'revolut_tokens' |
|
90 | + ], |
|
91 | 91 | |
92 | - 'cache' => [ |
|
93 | - 'driver' => null, |
|
94 | - ], |
|
95 | - ], |
|
92 | + 'cache' => [ |
|
93 | + 'driver' => null, |
|
94 | + ], |
|
95 | + ], |
|
96 | 96 | |
97 | - /* |
|
97 | + /* |
|
98 | 98 | |-------------------------------------------------------------------------- |
99 | 99 | | Authorization Route |
100 | 100 | |-------------------------------------------------------------------------- |
@@ -105,12 +105,12 @@ discard block |
||
105 | 105 | | therefore applied automatically and does not need to be specified |
106 | 106 | | |
107 | 107 | */ |
108 | - 'auth_route' => [ |
|
108 | + 'auth_route' => [ |
|
109 | 109 | |
110 | - 'name' => 'revolut-authorization', |
|
110 | + 'name' => 'revolut-authorization', |
|
111 | 111 | |
112 | - 'middleware' => [ |
|
113 | - // 'auth' |
|
114 | - ] |
|
115 | - ], |
|
112 | + 'middleware' => [ |
|
113 | + // 'auth' |
|
114 | + ] |
|
115 | + ], |
|
116 | 116 | ]; |
@@ -8,27 +8,27 @@ |
||
8 | 8 | |
9 | 9 | class DatabaseTokenRepository implements TokenRepository |
10 | 10 | { |
11 | - public function getAccessToken() |
|
12 | - { |
|
13 | - return AccessToken::active()->orderBy('id', 'desc')->first(); |
|
14 | - } |
|
11 | + public function getAccessToken() |
|
12 | + { |
|
13 | + return AccessToken::active()->orderBy('id', 'desc')->first(); |
|
14 | + } |
|
15 | 15 | |
16 | - public function getRefreshToken() |
|
17 | - { |
|
18 | - return RefreshToken::active()->orderBy('id', 'desc')->first(); |
|
19 | - } |
|
16 | + public function getRefreshToken() |
|
17 | + { |
|
18 | + return RefreshToken::active()->orderBy('id', 'desc')->first(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function createAccessToken(string $value) |
|
22 | - { |
|
23 | - return AccessToken::create([ |
|
24 | - 'value' => $value |
|
25 | - ]); |
|
26 | - } |
|
21 | + public function createAccessToken(string $value) |
|
22 | + { |
|
23 | + return AccessToken::create([ |
|
24 | + 'value' => $value |
|
25 | + ]); |
|
26 | + } |
|
27 | 27 | |
28 | - public function createRefreshToken(string $value) |
|
29 | - { |
|
30 | - return RefreshToken::create([ |
|
31 | - 'value' => $value |
|
32 | - ]); |
|
33 | - } |
|
28 | + public function createRefreshToken(string $value) |
|
29 | + { |
|
30 | + return RefreshToken::create([ |
|
31 | + 'value' => $value |
|
32 | + ]); |
|
33 | + } |
|
34 | 34 | } |
@@ -8,69 +8,69 @@ |
||
8 | 8 | |
9 | 9 | class RefreshToken extends Token implements GrantsAccessTokens, PersistableToken |
10 | 10 | { |
11 | - /** |
|
12 | - * The type of the token |
|
13 | - * |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - const TYPE = 'refresh_token'; |
|
11 | + /** |
|
12 | + * The type of the token |
|
13 | + * |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + const TYPE = 'refresh_token'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * The grant type of the token |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - const GRANT_TYPE = 'refresh_token'; |
|
18 | + /** |
|
19 | + * The grant type of the token |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + const GRANT_TYPE = 'refresh_token'; |
|
24 | 24 | |
25 | - public function getValue() |
|
26 | - { |
|
27 | - return $this->value; |
|
28 | - } |
|
25 | + public function getValue() |
|
26 | + { |
|
27 | + return $this->value; |
|
28 | + } |
|
29 | 29 | |
30 | - public static function getType() |
|
31 | - { |
|
32 | - return self::TYPE; |
|
33 | - } |
|
30 | + public static function getType() |
|
31 | + { |
|
32 | + return self::TYPE; |
|
33 | + } |
|
34 | 34 | |
35 | - public static function getGrantType() |
|
36 | - { |
|
37 | - return self::GRANT_TYPE; |
|
38 | - } |
|
35 | + public static function getGrantType() |
|
36 | + { |
|
37 | + return self::GRANT_TYPE; |
|
38 | + } |
|
39 | 39 | |
40 | - public static function getExpiration() |
|
41 | - { |
|
42 | - return config('revolut.expire_api_access', false) |
|
43 | - ? self::PSD2expiration() |
|
44 | - : null; |
|
45 | - } |
|
40 | + public static function getExpiration() |
|
41 | + { |
|
42 | + return config('revolut.expire_api_access', false) |
|
43 | + ? self::PSD2expiration() |
|
44 | + : null; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Delete all expired refresh tokens |
|
49 | - * |
|
50 | - * @return int The number of deleted tokens |
|
51 | - */ |
|
52 | - public static function clearExpired() |
|
53 | - { |
|
54 | - $latest = self::latest()->select('id')->first(); |
|
47 | + /** |
|
48 | + * Delete all expired refresh tokens |
|
49 | + * |
|
50 | + * @return int The number of deleted tokens |
|
51 | + */ |
|
52 | + public static function clearExpired() |
|
53 | + { |
|
54 | + $latest = self::latest()->select('id')->first(); |
|
55 | 55 | |
56 | - return (int) self::where('id', '!=', $latest->id)->delete(); |
|
57 | - } |
|
56 | + return (int) self::where('id', '!=', $latest->id)->delete(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Calculate the expiration date |
|
61 | - * |
|
62 | - * An expiration should be set if the account is subject to PSD2 regulation, |
|
63 | - * under which access to the API expires after 90 days. |
|
64 | - * When access to the API expires, existing access tokens may be revoked. |
|
65 | - * The refresh token should be treated as expired premajurely, to prevent it from |
|
66 | - * being used to request access tokens which may be revoked before their default |
|
67 | - * lifetime has expired. |
|
68 | - * |
|
69 | - * @see https://developer.revolut.com/docs/business-api/#getting-started-usage-and-limits |
|
70 | - * @return \Carbon\Carbon |
|
71 | - */ |
|
72 | - private static function PSD2expiration() |
|
73 | - { |
|
74 | - return now()->addDays(90)->subMinutes(AccessToken::TTL); |
|
75 | - } |
|
59 | + /** |
|
60 | + * Calculate the expiration date |
|
61 | + * |
|
62 | + * An expiration should be set if the account is subject to PSD2 regulation, |
|
63 | + * under which access to the API expires after 90 days. |
|
64 | + * When access to the API expires, existing access tokens may be revoked. |
|
65 | + * The refresh token should be treated as expired premajurely, to prevent it from |
|
66 | + * being used to request access tokens which may be revoked before their default |
|
67 | + * lifetime has expired. |
|
68 | + * |
|
69 | + * @see https://developer.revolut.com/docs/business-api/#getting-started-usage-and-limits |
|
70 | + * @return \Carbon\Carbon |
|
71 | + */ |
|
72 | + private static function PSD2expiration() |
|
73 | + { |
|
74 | + return now()->addDays(90)->subMinutes(AccessToken::TTL); |
|
75 | + } |
|
76 | 76 | } |