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
|
|
View Code Duplication |
$app->singleton(FluentClient::class, function ($app) use ($provider) { |
|
|
|
|
77
|
|
|
$limitClientsToGrants = $app['config']->get('oauth2.limit_clients_to_grants'); |
78
|
|
|
$limitRedirectUri = $app['config']->get('oauth2.limit_clients_to_predefined_url'); |
79
|
|
|
$storage = new FluentClient($provider->app['db'], $limitClientsToGrants, $limitRedirectUri); |
80
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
81
|
|
|
|
82
|
|
|
return $storage; |
83
|
108 |
|
}); |
84
|
|
|
|
85
|
|
View Code Duplication |
$app->singleton(FluentRefreshToken::class, function () use ($provider) { |
|
|
|
|
86
|
|
|
$storage = new FluentRefreshToken($provider->app['db']); |
87
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
88
|
|
|
|
89
|
|
|
return $storage; |
90
|
108 |
|
}); |
91
|
|
|
|
92
|
|
View Code Duplication |
$app->singleton(FluentScope::class, function ($app) use ($provider) { |
|
|
|
|
93
|
|
|
$limitClientsToScopes = $app['config']->get('oauth2.limit_clients_to_scopes'); |
94
|
|
|
$limitScopesToGrants = $app['config']->get('oauth2.limit_scopes_to_grants'); |
95
|
|
|
$storage = new FluentScope($provider->app['db'], $limitClientsToScopes, $limitScopesToGrants); |
96
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
97
|
|
|
|
98
|
|
|
return $storage; |
99
|
108 |
|
}); |
100
|
|
|
|
101
|
108 |
View Code Duplication |
$app->singleton(FluentSession::class, function () use ($provider) { |
|
|
|
|
102
|
|
|
$storage = new FluentSession($provider->app['db']); |
103
|
|
|
$storage->setConnectionName($provider->getConnectionName()); |
104
|
|
|
|
105
|
|
|
return $storage; |
106
|
108 |
|
}); |
107
|
108 |
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Bind the interfaces to their implementations. |
111
|
|
|
* |
112
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
|
|
|
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
108 |
|
public function registerInterfaceBindings(Application $app) |
117
|
|
|
{ |
118
|
108 |
|
$app->bind(ClientInterface::class, FluentClient::class); |
119
|
108 |
|
$app->bind(ScopeInterface::class, FluentScope::class); |
120
|
108 |
|
$app->bind(SessionInterface::class, FluentSession::class); |
121
|
108 |
|
$app->bind(AuthCodeInterface::class, FluentAuthCode::class); |
122
|
108 |
|
$app->bind(AccessTokenInterface::class, FluentAccessToken::class); |
123
|
108 |
|
$app->bind(RefreshTokenInterface::class, FluentRefreshToken::class); |
124
|
108 |
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getConnectionName() |
130
|
|
|
{ |
131
|
|
|
return ($this->app['config']->get('oauth2.database') !== 'default') ? $this->app['config']->get('oauth2.database') : null; |
|
|
|
|
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This check looks for
@param
annotations 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.