11
11
12
12
namespace LucaDegasperi \OAuth2Server ;
13
13
14
+ use Illuminate \Contracts \Foundation \Application ;
14
15
use Illuminate \Support \ServiceProvider ;
15
16
use League \OAuth2 \Server \AuthorizationServer ;
16
17
use League \OAuth2 \Server \ResourceServer ;
@@ -39,34 +40,44 @@ class OAuth2ServerServiceProvider extends ServiceProvider
39
40
*/
40
41
public function boot ()
41
42
{
42
- $ this ->setupConfig ();
43
- $ this ->setupMigrations ();
43
+ $ this ->setupConfig ($ this -> app );
44
+ $ this ->setupMigrations ($ this -> app );
44
45
}
45
46
46
47
/**
47
48
* Setup the config.
48
49
*
50
+ * @param \Illuminate\Contracts\Foundation\Application $app
51
+ *
49
52
* @return void
50
53
*/
51
- protected function setupConfig ()
54
+ protected function setupConfig (Application $ app )
52
55
{
53
56
$ source = realpath (__DIR__ .'/../config/oauth2.php ' );
54
57
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
+ }
56
63
57
64
$ this ->mergeConfigFrom ($ source , 'oauth2 ' );
58
65
}
59
66
60
67
/**
61
68
* Setup the migrations.
62
69
*
70
+ * @param \Illuminate\Contracts\Foundation\Application $app
71
+ *
63
72
* @return void
64
73
*/
65
- protected function setupMigrations ()
74
+ protected function setupMigrations (Application $ app )
66
75
{
67
76
$ source = realpath (__DIR__ .'/../database/migrations/ ' );
68
77
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
+ }
70
81
}
71
82
72
83
/**
@@ -90,17 +101,17 @@ public function registerAuthorizer()
90
101
$ this ->app ->bindShared ('oauth2-server.authorizer ' , function ($ app ) {
91
102
$ config = $ app ['config ' ]->get ('oauth2 ' );
92
103
$ 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 ' ]);
104
115
105
116
// add the supported grant types to the authorization server
106
117
foreach ($ config ['grant_types ' ] as $ grantIdentifier => $ grantParams ) {
@@ -112,15 +123,19 @@ public function registerAuthorizer()
112
123
$ verifier = $ app ->make ($ className );
113
124
$ grant ->setVerifyCredentialsCallback ([$ verifier , $ method ]);
114
125
}
126
+
115
127
if (array_key_exists ('auth_token_ttl ' , $ grantParams )) {
116
128
$ grant ->setAuthTokenTTL ($ grantParams ['auth_token_ttl ' ]);
117
129
}
130
+
118
131
if (array_key_exists ('refresh_token_ttl ' , $ grantParams )) {
119
132
$ grant ->setRefreshTokenTTL ($ grantParams ['refresh_token_ttl ' ]);
120
133
}
134
+
121
135
if (array_key_exists ('rotate_refresh_tokens ' , $ grantParams )) {
122
136
$ grant ->setRefreshTokenRotation ($ grantParams ['rotate_refresh_tokens ' ]);
123
137
}
138
+
124
139
$ issuer ->addGrantType ($ grant );
125
140
}
126
141
@@ -141,7 +156,8 @@ public function registerAuthorizer()
141
156
}
142
157
143
158
/**
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.
145
161
*
146
162
* @return void
147
163
*/
0 commit comments