|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of OAuth 2.0 Laravel. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Luca Degasperi <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LucaDegasperi\OAuth2Server\Storage; |
|
13
|
|
|
|
|
14
|
|
|
use Illuminate\Contracts\Container\Container as Application; |
|
15
|
|
|
use Illuminate\Support\ServiceProvider; |
|
16
|
|
|
use League\OAuth2\Server\Storage\AccessTokenInterface; |
|
17
|
|
|
use League\OAuth2\Server\Storage\AuthCodeInterface; |
|
18
|
|
|
use League\OAuth2\Server\Storage\ClientInterface; |
|
19
|
|
|
use League\OAuth2\Server\Storage\RefreshTokenInterface; |
|
20
|
|
|
use League\OAuth2\Server\Storage\ScopeInterface; |
|
21
|
|
|
use League\OAuth2\Server\Storage\SessionInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* This is the fluent storage service provider class. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Luca Degasperi <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class FluentStorageServiceProvider extends ServiceProvider |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Bootstrap the application events. |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
108 |
|
public function boot() |
|
36
|
|
|
{ |
|
37
|
|
|
// |
|
38
|
108 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Register the service provider. |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
108 |
|
public function register() |
|
46
|
|
|
{ |
|
47
|
108 |
|
$this->registerStorageBindings($this->app); |
|
48
|
108 |
|
$this->registerInterfaceBindings($this->app); |
|
49
|
108 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Bind the storage implementations to the IoC container. |
|
53
|
|
|
* |
|
54
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
|
|
|
|
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
108 |
|
public function registerStorageBindings(Application $app) |
|
59
|
|
|
{ |
|
60
|
108 |
|
$provider = $this; |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
$app->singleton(FluentAccessToken::class, function () use ($provider) { |
|
|
|
|
|
|
63
|
|
|
$storage = new FluentAccessToken($provider->app['db']); |
|
64
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
|
65
|
|
|
|
|
66
|
|
|
return $storage; |
|
67
|
108 |
|
}); |
|
68
|
|
|
|
|
69
|
|
View Code Duplication |
$app->singleton(FluentAuthCode::class, function () use ($provider) { |
|
|
|
|
|
|
70
|
|
|
$storage = new FluentAuthCode($provider->app['db']); |
|
71
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
|
72
|
|
|
|
|
73
|
|
|
return $storage; |
|
74
|
108 |
|
}); |
|
75
|
|
|
|
|
76
|
|
|
$app->singleton(FluentClient::class, function ($app) use ($provider) { |
|
77
|
|
|
$limitClientsToGrants = $app['config']->get('oauth2.limit_clients_to_grants'); |
|
78
|
|
|
$storage = new FluentClient($provider->app['db'], $limitClientsToGrants); |
|
79
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
|
80
|
|
|
|
|
81
|
|
|
return $storage; |
|
82
|
108 |
|
}); |
|
83
|
|
|
|
|
84
|
|
View Code Duplication |
$app->singleton(FluentRefreshToken::class, function () use ($provider) { |
|
|
|
|
|
|
85
|
|
|
$storage = new FluentRefreshToken($provider->app['db']); |
|
86
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
|
87
|
|
|
|
|
88
|
|
|
return $storage; |
|
89
|
108 |
|
}); |
|
90
|
|
|
|
|
91
|
|
|
$app->singleton(FluentScope::class, function ($app) use ($provider) { |
|
92
|
|
|
$limitClientsToScopes = $app['config']->get('oauth2.limit_clients_to_scopes'); |
|
93
|
|
|
$limitScopesToGrants = $app['config']->get('oauth2.limit_scopes_to_grants'); |
|
94
|
|
|
$storage = new FluentScope($provider->app['db'], $limitClientsToScopes, $limitScopesToGrants); |
|
95
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
|
96
|
|
|
|
|
97
|
|
|
return $storage; |
|
98
|
108 |
|
}); |
|
99
|
|
|
|
|
100
|
108 |
View Code Duplication |
$app->singleton(FluentSession::class, function () use ($provider) { |
|
|
|
|
|
|
101
|
|
|
$storage = new FluentSession($provider->app['db']); |
|
102
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
|
103
|
|
|
|
|
104
|
|
|
return $storage; |
|
105
|
108 |
|
}); |
|
106
|
108 |
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Bind the interfaces to their implementations. |
|
110
|
|
|
* |
|
111
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
|
|
|
|
|
112
|
|
|
* |
|
113
|
|
|
* @return void |
|
114
|
|
|
*/ |
|
115
|
108 |
|
public function registerInterfaceBindings(Application $app) |
|
116
|
|
|
{ |
|
117
|
108 |
|
$app->bind(ClientInterface::class, FluentClient::class); |
|
118
|
108 |
|
$app->bind(ScopeInterface::class, FluentScope::class); |
|
119
|
108 |
|
$app->bind(SessionInterface::class, FluentSession::class); |
|
120
|
108 |
|
$app->bind(AuthCodeInterface::class, FluentAuthCode::class); |
|
121
|
108 |
|
$app->bind(AccessTokenInterface::class, FluentAccessToken::class); |
|
122
|
108 |
|
$app->bind(RefreshTokenInterface::class, FluentRefreshToken::class); |
|
123
|
108 |
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return string |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getConnectionName() |
|
129
|
|
|
{ |
|
130
|
|
|
return ($this->app['config']->get('oauth2.database') !== 'default') ? $this->app['config']->get('oauth2.database') : null; |
|
|
|
|
|
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.