22
33namespace dokuwiki \plugin \oauth ;
44
5+ use dokuwiki \Extension \EventHandler ;
6+ use dokuwiki \Extension \Event ;
57use dokuwiki \Extension \ActionPlugin ;
68use OAuth \Common \Consumer \Credentials ;
79use OAuth \Common \Http \Exception \TokenResponseException ;
@@ -32,15 +34,15 @@ abstract class Adapter extends ActionPlugin
3234 *
3335 * @inheritDoc
3436 */
35- public function register (\ Doku_Event_Handler $ controller )
37+ public function register (EventHandler $ controller )
3638 {
3739 $ controller ->register_hook ('PLUGIN_OAUTH_BACKEND_REGISTER ' , 'AFTER ' , $ this , 'handleRegister ' );
3840 }
3941
4042 /**
4143 * Auto register this plugin with the oAuth authentication plugin
4244 */
43- public function handleRegister (\ Doku_Event $ event , $ param )
45+ public function handleRegister (Event $ event , $ param )
4446 {
4547 $ event ->data [$ this ->getServiceID ()] = $ this ;
4648 }
@@ -64,6 +66,7 @@ public function initOAuthService($storageId = '')
6466
6567 $ serviceFactory = new ServiceFactory ();
6668 $ serviceFactory ->setHttpClient (new HTTPClient ());
69+
6770 $ servicename = $ this ->getServiceID ();
6871 $ serviceclass = $ this ->registerServiceClass ();
6972 if ($ serviceclass ) {
@@ -143,8 +146,10 @@ public function refreshOutdatedToken()
143146 }
144147
145148 $ token = $ oauth ->getStorage ()->retrieveAccessToken ($ oauth ->service ());
146- if ($ token ->getEndOfLife () < 0 ||
147- $ token ->getEndOfLife () - time () > 3600 ) {
149+ if (
150+ $ token ->getEndOfLife () < 0 ||
151+ $ token ->getEndOfLife () - time () > 3600
152+ ) {
148153 // token is still good
149154 return ;
150155 }
@@ -168,7 +173,7 @@ public function refreshOutdatedToken()
168173 * but might need to be overwritten for specific services
169174 *
170175 * @throws TokenResponseException
171- * @throws Exception
176+ * @throws \ Exception
172177 */
173178 public function login ()
174179 {
@@ -182,7 +187,7 @@ public function login()
182187 $ parameters ['state ' ] = urlencode (base64_encode (json_encode (
183188 [
184189 'animal ' => $ animal ,
185- 'state ' => md5 (rand ( )),
190+ 'state ' => md5 (random_int ( 0 , mt_getrandmax () )),
186191 ]
187192 )));
188193 $ oauth ->getStorage ()->storeAuthorizationState ($ oauth ->service (), $ parameters ['state ' ]);
@@ -221,12 +226,10 @@ public function checkToken()
221226 $ oauth = $ this ->getOAuthService ();
222227
223228 if (is_a ($ oauth , Abstract2Service::class)) {
224- /** @var Abstract2Service $oauth */
225229 if (!$ INPUT ->get ->has ('code ' )) return false ;
226230 $ state = $ INPUT ->get ->str ('state ' , null );
227231 $ accessToken = $ oauth ->requestAccessToken ($ INPUT ->get ->str ('code ' ), $ state );
228232 } else {
229- /** @var Abstract1Service $oauth */
230233 if (!$ INPUT ->get ->has ('oauth_token ' )) return false ;
231234 /** @var TokenInterface $token */
232235 $ token = $ oauth ->getStorage ()->retrieveAccessToken ($ this ->getServiceID ());
@@ -239,7 +242,8 @@ public function checkToken()
239242
240243 if (
241244 $ accessToken ->getEndOfLife () !== $ accessToken ::EOL_NEVER_EXPIRES &&
242- !$ accessToken ->getRefreshToken ()) {
245+ !$ accessToken ->getRefreshToken ()
246+ ) {
243247 msg ('Service did not provide a Refresh Token. You will be logged out when the session expires. ' );
244248 }
245249
@@ -256,7 +260,7 @@ public function loginButton()
256260 global $ ID ;
257261
258262 $ attr = buildAttributes ([
259- 'href ' => wl ($ ID , array ( 'oauthlogin ' => $ this ->getServiceID ()) , false , '& ' ),
263+ 'href ' => wl ($ ID , [ 'oauthlogin ' => $ this ->getServiceID ()] , false , '& ' ),
260264 'class ' => 'plugin_oauth_ ' . $ this ->getServiceID (),
261265 'style ' => 'background-color: ' . $ this ->getColor (),
262266 ]);
0 commit comments