Skip to content

Commit 8c42e67

Browse files
committed
Update service provider
1 parent e12b558 commit 8c42e67

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

src/OAuth2ServerServiceProvider.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace LucaDegasperi\OAuth2Server;
1313

14+
use Illuminate\Contracts\Foundation\Application;
1415
use Illuminate\Support\ServiceProvider;
1516
use League\OAuth2\Server\AuthorizationServer;
1617
use League\OAuth2\Server\ResourceServer;
@@ -39,34 +40,44 @@ class OAuth2ServerServiceProvider extends ServiceProvider
3940
*/
4041
public function boot()
4142
{
42-
$this->setupConfig();
43-
$this->setupMigrations();
43+
$this->setupConfig($this->app);
44+
$this->setupMigrations($this->app);
4445
}
4546

4647
/**
4748
* Setup the config.
4849
*
50+
* @param \Illuminate\Contracts\Foundation\Application $app
51+
*
4952
* @return void
5053
*/
51-
protected function setupConfig()
54+
protected function setupConfig(Application $app)
5255
{
5356
$source = realpath(__DIR__.'/../config/oauth2.php');
5457

55-
$this->publishes([$source => config_path('oauth2.php')]);
58+
if (class_exists('Illuminate\Foundation\Application', false) && $app->runningInConsole()) {
59+
$this->publishes([$source => config_path('oauth2.php')]);
60+
} elseif (class_exists('Laravel\Lumen\Application', false)) {
61+
$app->configure('oauth2');
62+
}
5663

5764
$this->mergeConfigFrom($source, 'oauth2');
5865
}
5966

6067
/**
6168
* Setup the migrations.
6269
*
70+
* @param \Illuminate\Contracts\Foundation\Application $app
71+
*
6372
* @return void
6473
*/
65-
protected function setupMigrations()
74+
protected function setupMigrations(Application $app)
6675
{
6776
$source = realpath(__DIR__.'/../database/migrations/');
6877

69-
$this->publishes([$source => database_path('migrations')], 'migrations');
78+
if (class_exists('Illuminate\Foundation\Application', false) && $app->runningInConsole()) {
79+
$this->publishes([$source => database_path('migrations')], 'migrations');
80+
}
7081
}
7182

7283
/**
@@ -90,17 +101,17 @@ public function registerAuthorizer()
90101
$this->app->bindShared('oauth2-server.authorizer', function ($app) {
91102
$config = $app['config']->get('oauth2');
92103
$issuer = $app->make(AuthorizationServer::class)
93-
->setClientStorage($app->make(ClientInterface::class))
94-
->setSessionStorage($app->make(SessionInterface::class))
95-
->setAuthCodeStorage($app->make(AuthCodeInterface::class))
96-
->setAccessTokenStorage($app->make(AccessTokenInterface::class))
97-
->setRefreshTokenStorage($app->make(RefreshTokenInterface::class))
98-
->setScopeStorage($app->make(ScopeInterface::class))
99-
->requireScopeParam($config['scope_param'])
100-
->setDefaultScope($config['default_scope'])
101-
->requireStateParam($config['state_param'])
102-
->setScopeDelimiter($config['scope_delimiter'])
103-
->setAccessTokenTTL($config['access_token_ttl']);
104+
->setClientStorage($app->make(ClientInterface::class))
105+
->setSessionStorage($app->make(SessionInterface::class))
106+
->setAuthCodeStorage($app->make(AuthCodeInterface::class))
107+
->setAccessTokenStorage($app->make(AccessTokenInterface::class))
108+
->setRefreshTokenStorage($app->make(RefreshTokenInterface::class))
109+
->setScopeStorage($app->make(ScopeInterface::class))
110+
->requireScopeParam($config['scope_param'])
111+
->setDefaultScope($config['default_scope'])
112+
->requireStateParam($config['state_param'])
113+
->setScopeDelimiter($config['scope_delimiter'])
114+
->setAccessTokenTTL($config['access_token_ttl']);
104115

105116
// add the supported grant types to the authorization server
106117
foreach ($config['grant_types'] as $grantIdentifier => $grantParams) {
@@ -112,15 +123,19 @@ public function registerAuthorizer()
112123
$verifier = $app->make($className);
113124
$grant->setVerifyCredentialsCallback([$verifier, $method]);
114125
}
126+
115127
if (array_key_exists('auth_token_ttl', $grantParams)) {
116128
$grant->setAuthTokenTTL($grantParams['auth_token_ttl']);
117129
}
130+
118131
if (array_key_exists('refresh_token_ttl', $grantParams)) {
119132
$grant->setRefreshTokenTTL($grantParams['refresh_token_ttl']);
120133
}
134+
121135
if (array_key_exists('rotate_refresh_tokens', $grantParams)) {
122136
$grant->setRefreshTokenRotation($grantParams['rotate_refresh_tokens']);
123137
}
138+
124139
$issuer->addGrantType($grant);
125140
}
126141

@@ -141,7 +156,8 @@ public function registerAuthorizer()
141156
}
142157

143158
/**
144-
* Register the Middleware to the IoC container because some middleware need additional parameters.
159+
* Register the Middleware to the IoC container because
160+
* some middleware need additional parameters.
145161
*
146162
* @return void
147163
*/

0 commit comments

Comments
 (0)