Skip to content

Commit feca570

Browse files
committed
Merge pull request #564 from lucadegasperi/lumen
Improved Lumen support
2 parents e12b558 + 29828f8 commit feca570

File tree

6 files changed

+46
-61
lines changed

6 files changed

+46
-61
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 5.1.0 (upcoming)
4+
5+
- Improved Lumen support
6+
37
## 5.0.1 (released 2015-08-19)
48

59
- Added middleware registration

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
},
5050
"extra": {
5151
"branch-alias": {
52-
"dev-master": "5.0-dev"
52+
"dev-master": "5.1-dev"
5353
}
5454
},
5555
"minimum-stability": "dev",

src/Lumen/OAuth2ServerServiceProvider.php

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,16 @@
1111

1212
namespace LucaDegasperi\OAuth2Server\Lumen;
1313

14-
use LucaDegasperi\OAuth2Server\OAuth2ServerServiceProvider as BaseOAuth2ServerServiceProvider;
14+
use LucaDegasperi\OAuth2Server\OAuth2ServerServiceProvider as ServiceProvider;
1515

1616
/**
1717
* This is the Lumen oauth server service provider class.
1818
*
19+
* @deprecated since version 5.1. Use the base OAuth2ServerServiceProvider instead.
20+
*
1921
* @author Luca Degasperi <[email protected]>
2022
*/
21-
class OAuth2ServerServiceProvider extends BaseOAuth2ServerServiceProvider
23+
class OAuth2ServerServiceProvider extends ServiceProvider
2224
{
23-
/**
24-
* Boot the service provider.
25-
*
26-
* @return void
27-
*/
28-
public function boot()
29-
{
30-
// Lumen does not support route filters.
31-
}
32-
33-
/**
34-
* Register the service provider.
35-
*
36-
* @return void
37-
*/
38-
public function register()
39-
{
40-
parent::register();
41-
42-
$this->registerConfiguration();
43-
}
44-
45-
/**
46-
* Register the configuration.
47-
*
48-
* @return void
49-
*/
50-
public function registerConfiguration()
51-
{
52-
$this->app->configure('oauth2');
53-
}
25+
//
5426
}

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
*/

tests/functional/bootstrap/FeatureContext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function down()
3131
{
3232
$this->resetMigrations();
3333
}
34+
3435
/**
3536
* @Given /^An authorization server exists that supports the "([^"]*)" grant type$/
3637
*/

tests/unit/LucaDegasperi/OAuth2Server/AuthorizerSpec.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use League\OAuth2\Server\Entity\SessionEntity;
1818
use League\OAuth2\Server\Grant\AuthCodeGrant;
1919
use League\OAuth2\Server\ResourceServer;
20-
use League\OAuth2\Server\TokenType\TokenTypeInterface;
2120
use League\OAuth2\Server\Util\RedirectUri;
2221
use PhpSpec\ObjectBehavior;
2322
use Symfony\Component\HttpFoundation\Request;
@@ -28,6 +27,7 @@ public function let(AuthorizationServer $issuer, ResourceServer $checker)
2827
{
2928
$this->beConstructedWith($issuer, $checker);
3029
}
30+
3131
public function it_is_initializable()
3232
{
3333
$this->shouldHaveType('LucaDegasperi\OAuth2Server\Authorizer');
@@ -161,12 +161,4 @@ public function it_sets_a_redirect_uri_generator(RedirectUri $redirectUri)
161161

162162
$this->getRedirectUriGenerator()->shouldReturn($redirectUri);
163163
}
164-
165-
/*function it_sets_a_custom_token_type(AuthorizationServer $issuer, ResourceServer $checker, TokenTypeInterface $tokenType)
166-
{
167-
$issuer->setTokenType($tokenType)->shouldBeCalled();
168-
$checker->setTokenType($tokenType)->shouldBeCalled();
169-
170-
$this->setTokenType($tokenType);
171-
}*/
172164
}

0 commit comments

Comments
 (0)