Passed
Push — master ( 68f046...9f6414 )
by John
11:58
created
core/Controller/ClientFlowLoginController.php 2 patches
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -48,303 +48,303 @@
 block discarded – undo
48 48
 use OCP\Session\Exceptions\SessionNotAvailableException;
49 49
 
50 50
 class ClientFlowLoginController extends Controller {
51
-	/** @var IUserSession */
52
-	private $userSession;
53
-	/** @var IL10N */
54
-	private $l10n;
55
-	/** @var Defaults */
56
-	private $defaults;
57
-	/** @var ISession */
58
-	private $session;
59
-	/** @var IProvider */
60
-	private $tokenProvider;
61
-	/** @var ISecureRandom */
62
-	private $random;
63
-	/** @var IURLGenerator */
64
-	private $urlGenerator;
65
-	/** @var ClientMapper */
66
-	private $clientMapper;
67
-	/** @var AccessTokenMapper */
68
-	private $accessTokenMapper;
69
-	/** @var ICrypto */
70
-	private $crypto;
51
+    /** @var IUserSession */
52
+    private $userSession;
53
+    /** @var IL10N */
54
+    private $l10n;
55
+    /** @var Defaults */
56
+    private $defaults;
57
+    /** @var ISession */
58
+    private $session;
59
+    /** @var IProvider */
60
+    private $tokenProvider;
61
+    /** @var ISecureRandom */
62
+    private $random;
63
+    /** @var IURLGenerator */
64
+    private $urlGenerator;
65
+    /** @var ClientMapper */
66
+    private $clientMapper;
67
+    /** @var AccessTokenMapper */
68
+    private $accessTokenMapper;
69
+    /** @var ICrypto */
70
+    private $crypto;
71 71
 
72
-	const stateName = 'client.flow.state.token';
72
+    const stateName = 'client.flow.state.token';
73 73
 
74
-	/**
75
-	 * @param string $appName
76
-	 * @param IRequest $request
77
-	 * @param IUserSession $userSession
78
-	 * @param IL10N $l10n
79
-	 * @param Defaults $defaults
80
-	 * @param ISession $session
81
-	 * @param IProvider $tokenProvider
82
-	 * @param ISecureRandom $random
83
-	 * @param IURLGenerator $urlGenerator
84
-	 * @param ClientMapper $clientMapper
85
-	 * @param AccessTokenMapper $accessTokenMapper
86
-	 * @param ICrypto $crypto
87
-	 */
88
-	public function __construct($appName,
89
-								IRequest $request,
90
-								IUserSession $userSession,
91
-								IL10N $l10n,
92
-								Defaults $defaults,
93
-								ISession $session,
94
-								IProvider $tokenProvider,
95
-								ISecureRandom $random,
96
-								IURLGenerator $urlGenerator,
97
-								ClientMapper $clientMapper,
98
-								AccessTokenMapper $accessTokenMapper,
99
-								ICrypto $crypto) {
100
-		parent::__construct($appName, $request);
101
-		$this->userSession = $userSession;
102
-		$this->l10n = $l10n;
103
-		$this->defaults = $defaults;
104
-		$this->session = $session;
105
-		$this->tokenProvider = $tokenProvider;
106
-		$this->random = $random;
107
-		$this->urlGenerator = $urlGenerator;
108
-		$this->clientMapper = $clientMapper;
109
-		$this->accessTokenMapper = $accessTokenMapper;
110
-		$this->crypto = $crypto;
111
-	}
74
+    /**
75
+     * @param string $appName
76
+     * @param IRequest $request
77
+     * @param IUserSession $userSession
78
+     * @param IL10N $l10n
79
+     * @param Defaults $defaults
80
+     * @param ISession $session
81
+     * @param IProvider $tokenProvider
82
+     * @param ISecureRandom $random
83
+     * @param IURLGenerator $urlGenerator
84
+     * @param ClientMapper $clientMapper
85
+     * @param AccessTokenMapper $accessTokenMapper
86
+     * @param ICrypto $crypto
87
+     */
88
+    public function __construct($appName,
89
+                                IRequest $request,
90
+                                IUserSession $userSession,
91
+                                IL10N $l10n,
92
+                                Defaults $defaults,
93
+                                ISession $session,
94
+                                IProvider $tokenProvider,
95
+                                ISecureRandom $random,
96
+                                IURLGenerator $urlGenerator,
97
+                                ClientMapper $clientMapper,
98
+                                AccessTokenMapper $accessTokenMapper,
99
+                                ICrypto $crypto) {
100
+        parent::__construct($appName, $request);
101
+        $this->userSession = $userSession;
102
+        $this->l10n = $l10n;
103
+        $this->defaults = $defaults;
104
+        $this->session = $session;
105
+        $this->tokenProvider = $tokenProvider;
106
+        $this->random = $random;
107
+        $this->urlGenerator = $urlGenerator;
108
+        $this->clientMapper = $clientMapper;
109
+        $this->accessTokenMapper = $accessTokenMapper;
110
+        $this->crypto = $crypto;
111
+    }
112 112
 
113
-	/**
114
-	 * @return string
115
-	 */
116
-	private function getClientName() {
117
-		$userAgent = $this->request->getHeader('USER_AGENT');
118
-		return $userAgent !== '' ? $userAgent : 'unknown';
119
-	}
113
+    /**
114
+     * @return string
115
+     */
116
+    private function getClientName() {
117
+        $userAgent = $this->request->getHeader('USER_AGENT');
118
+        return $userAgent !== '' ? $userAgent : 'unknown';
119
+    }
120 120
 
121
-	/**
122
-	 * @param string $stateToken
123
-	 * @return bool
124
-	 */
125
-	private function isValidToken($stateToken) {
126
-		$currentToken = $this->session->get(self::stateName);
127
-		if(!is_string($stateToken) || !is_string($currentToken)) {
128
-			return false;
129
-		}
130
-		return hash_equals($currentToken, $stateToken);
131
-	}
121
+    /**
122
+     * @param string $stateToken
123
+     * @return bool
124
+     */
125
+    private function isValidToken($stateToken) {
126
+        $currentToken = $this->session->get(self::stateName);
127
+        if(!is_string($stateToken) || !is_string($currentToken)) {
128
+            return false;
129
+        }
130
+        return hash_equals($currentToken, $stateToken);
131
+    }
132 132
 
133
-	/**
134
-	 * @return TemplateResponse
135
-	 */
136
-	private function stateTokenForbiddenResponse() {
137
-		$response = new TemplateResponse(
138
-			$this->appName,
139
-			'403',
140
-			[
141
-				'file' => $this->l10n->t('State token does not match'),
142
-			],
143
-			'guest'
144
-		);
145
-		$response->setStatus(Http::STATUS_FORBIDDEN);
146
-		return $response;
147
-	}
133
+    /**
134
+     * @return TemplateResponse
135
+     */
136
+    private function stateTokenForbiddenResponse() {
137
+        $response = new TemplateResponse(
138
+            $this->appName,
139
+            '403',
140
+            [
141
+                'file' => $this->l10n->t('State token does not match'),
142
+            ],
143
+            'guest'
144
+        );
145
+        $response->setStatus(Http::STATUS_FORBIDDEN);
146
+        return $response;
147
+    }
148 148
 
149
-	/**
150
-	 * @PublicPage
151
-	 * @NoCSRFRequired
152
-	 * @UseSession
153
-	 *
154
-	 * @param string $clientIdentifier
155
-	 *
156
-	 * @return TemplateResponse
157
-	 */
158
-	public function showAuthPickerPage($clientIdentifier = '') {
159
-		$clientName = $this->getClientName();
160
-		$client = null;
161
-		if($clientIdentifier !== '') {
162
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
163
-			$clientName = $client->getName();
164
-		}
149
+    /**
150
+     * @PublicPage
151
+     * @NoCSRFRequired
152
+     * @UseSession
153
+     *
154
+     * @param string $clientIdentifier
155
+     *
156
+     * @return TemplateResponse
157
+     */
158
+    public function showAuthPickerPage($clientIdentifier = '') {
159
+        $clientName = $this->getClientName();
160
+        $client = null;
161
+        if($clientIdentifier !== '') {
162
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
163
+            $clientName = $client->getName();
164
+        }
165 165
 
166
-		// No valid clientIdentifier given and no valid API Request (APIRequest header not set)
167
-		$clientRequest = $this->request->getHeader('OCS-APIREQUEST');
168
-		if ($clientRequest !== 'true' && $client === null) {
169
-			return new TemplateResponse(
170
-				$this->appName,
171
-				'error',
172
-				[
173
-					'errors' =>
174
-					[
175
-						[
176
-							'error' => 'Access Forbidden',
177
-							'hint' => 'Invalid request',
178
-						],
179
-					],
180
-				],
181
-				'guest'
182
-			);
183
-		}
166
+        // No valid clientIdentifier given and no valid API Request (APIRequest header not set)
167
+        $clientRequest = $this->request->getHeader('OCS-APIREQUEST');
168
+        if ($clientRequest !== 'true' && $client === null) {
169
+            return new TemplateResponse(
170
+                $this->appName,
171
+                'error',
172
+                [
173
+                    'errors' =>
174
+                    [
175
+                        [
176
+                            'error' => 'Access Forbidden',
177
+                            'hint' => 'Invalid request',
178
+                        ],
179
+                    ],
180
+                ],
181
+                'guest'
182
+            );
183
+        }
184 184
 
185
-		$stateToken = $this->random->generate(
186
-			64,
187
-			ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS
188
-		);
189
-		$this->session->set(self::stateName, $stateToken);
185
+        $stateToken = $this->random->generate(
186
+            64,
187
+            ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS
188
+        );
189
+        $this->session->set(self::stateName, $stateToken);
190 190
 
191
-		return new TemplateResponse(
192
-			$this->appName,
193
-			'loginflow/authpicker',
194
-			[
195
-				'client' => $clientName,
196
-				'clientIdentifier' => $clientIdentifier,
197
-				'instanceName' => $this->defaults->getName(),
198
-				'urlGenerator' => $this->urlGenerator,
199
-				'stateToken' => $stateToken,
200
-				'serverHost' => $this->getServerPath(),
201
-				'oauthState' => $this->session->get('oauth.state'),
202
-			],
203
-			'guest'
204
-		);
205
-	}
191
+        return new TemplateResponse(
192
+            $this->appName,
193
+            'loginflow/authpicker',
194
+            [
195
+                'client' => $clientName,
196
+                'clientIdentifier' => $clientIdentifier,
197
+                'instanceName' => $this->defaults->getName(),
198
+                'urlGenerator' => $this->urlGenerator,
199
+                'stateToken' => $stateToken,
200
+                'serverHost' => $this->getServerPath(),
201
+                'oauthState' => $this->session->get('oauth.state'),
202
+            ],
203
+            'guest'
204
+        );
205
+    }
206 206
 
207
-	/**
208
-	 * @NoAdminRequired
209
-	 * @NoCSRFRequired
210
-	 * @UseSession
211
-	 *
212
-	 * @param string $stateToken
213
-	 * @param string $clientIdentifier
214
-	 * @return TemplateResponse
215
-	 */
216
-	public function grantPage($stateToken = '',
217
-								 $clientIdentifier = '') {
218
-		if(!$this->isValidToken($stateToken)) {
219
-			return $this->stateTokenForbiddenResponse();
220
-		}
207
+    /**
208
+     * @NoAdminRequired
209
+     * @NoCSRFRequired
210
+     * @UseSession
211
+     *
212
+     * @param string $stateToken
213
+     * @param string $clientIdentifier
214
+     * @return TemplateResponse
215
+     */
216
+    public function grantPage($stateToken = '',
217
+                                    $clientIdentifier = '') {
218
+        if(!$this->isValidToken($stateToken)) {
219
+            return $this->stateTokenForbiddenResponse();
220
+        }
221 221
 
222
-		$clientName = $this->getClientName();
223
-		$client = null;
224
-		if($clientIdentifier !== '') {
225
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
226
-			$clientName = $client->getName();
227
-		}
222
+        $clientName = $this->getClientName();
223
+        $client = null;
224
+        if($clientIdentifier !== '') {
225
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
226
+            $clientName = $client->getName();
227
+        }
228 228
 
229
-		return new TemplateResponse(
230
-			$this->appName,
231
-			'loginflow/grant',
232
-			[
233
-				'client' => $clientName,
234
-				'clientIdentifier' => $clientIdentifier,
235
-				'instanceName' => $this->defaults->getName(),
236
-				'urlGenerator' => $this->urlGenerator,
237
-				'stateToken' => $stateToken,
238
-				'serverHost' => $this->getServerPath(),
239
-				'oauthState' => $this->session->get('oauth.state'),
240
-			],
241
-			'guest'
242
-		);
243
-	}
229
+        return new TemplateResponse(
230
+            $this->appName,
231
+            'loginflow/grant',
232
+            [
233
+                'client' => $clientName,
234
+                'clientIdentifier' => $clientIdentifier,
235
+                'instanceName' => $this->defaults->getName(),
236
+                'urlGenerator' => $this->urlGenerator,
237
+                'stateToken' => $stateToken,
238
+                'serverHost' => $this->getServerPath(),
239
+                'oauthState' => $this->session->get('oauth.state'),
240
+            ],
241
+            'guest'
242
+        );
243
+    }
244 244
 
245
-	/**
246
-	 * @NoAdminRequired
247
-	 * @UseSession
248
-	 *
249
-	 * @param string $stateToken
250
-	 * @param string $clientIdentifier
251
-	 * @return Http\RedirectResponse|Response
252
-	 */
253
-	public function generateAppPassword($stateToken,
254
-										$clientIdentifier = '') {
255
-		if(!$this->isValidToken($stateToken)) {
256
-			$this->session->remove(self::stateName);
257
-			return $this->stateTokenForbiddenResponse();
258
-		}
245
+    /**
246
+     * @NoAdminRequired
247
+     * @UseSession
248
+     *
249
+     * @param string $stateToken
250
+     * @param string $clientIdentifier
251
+     * @return Http\RedirectResponse|Response
252
+     */
253
+    public function generateAppPassword($stateToken,
254
+                                        $clientIdentifier = '') {
255
+        if(!$this->isValidToken($stateToken)) {
256
+            $this->session->remove(self::stateName);
257
+            return $this->stateTokenForbiddenResponse();
258
+        }
259 259
 
260
-		$this->session->remove(self::stateName);
260
+        $this->session->remove(self::stateName);
261 261
 
262
-		try {
263
-			$sessionId = $this->session->getId();
264
-		} catch (SessionNotAvailableException $ex) {
265
-			$response = new Response();
266
-			$response->setStatus(Http::STATUS_FORBIDDEN);
267
-			return $response;
268
-		}
262
+        try {
263
+            $sessionId = $this->session->getId();
264
+        } catch (SessionNotAvailableException $ex) {
265
+            $response = new Response();
266
+            $response->setStatus(Http::STATUS_FORBIDDEN);
267
+            return $response;
268
+        }
269 269
 
270
-		try {
271
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
272
-			$loginName = $sessionToken->getLoginName();
273
-			try {
274
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
275
-			} catch (PasswordlessTokenException $ex) {
276
-				$password = null;
277
-			}
278
-		} catch (InvalidTokenException $ex) {
279
-			$response = new Response();
280
-			$response->setStatus(Http::STATUS_FORBIDDEN);
281
-			return $response;
282
-		}
270
+        try {
271
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
272
+            $loginName = $sessionToken->getLoginName();
273
+            try {
274
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
275
+            } catch (PasswordlessTokenException $ex) {
276
+                $password = null;
277
+            }
278
+        } catch (InvalidTokenException $ex) {
279
+            $response = new Response();
280
+            $response->setStatus(Http::STATUS_FORBIDDEN);
281
+            return $response;
282
+        }
283 283
 
284
-		$clientName = $this->getClientName();
285
-		$client = false;
286
-		if($clientIdentifier !== '') {
287
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
288
-			$clientName = $client->getName();
289
-		}
284
+        $clientName = $this->getClientName();
285
+        $client = false;
286
+        if($clientIdentifier !== '') {
287
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
288
+            $clientName = $client->getName();
289
+        }
290 290
 
291
-		$token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
292
-		$uid = $this->userSession->getUser()->getUID();
293
-		$generatedToken = $this->tokenProvider->generateToken(
294
-			$token,
295
-			$uid,
296
-			$loginName,
297
-			$password,
298
-			$clientName,
299
-			IToken::PERMANENT_TOKEN,
300
-			IToken::DO_NOT_REMEMBER
301
-		);
291
+        $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
292
+        $uid = $this->userSession->getUser()->getUID();
293
+        $generatedToken = $this->tokenProvider->generateToken(
294
+            $token,
295
+            $uid,
296
+            $loginName,
297
+            $password,
298
+            $clientName,
299
+            IToken::PERMANENT_TOKEN,
300
+            IToken::DO_NOT_REMEMBER
301
+        );
302 302
 
303
-		if($client) {
304
-			$code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
305
-			$accessToken = new AccessToken();
306
-			$accessToken->setClientId($client->getId());
307
-			$accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
308
-			$accessToken->setHashedCode(hash('sha512', $code));
309
-			$accessToken->setTokenId($generatedToken->getId());
310
-			$this->accessTokenMapper->insert($accessToken);
303
+        if($client) {
304
+            $code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
305
+            $accessToken = new AccessToken();
306
+            $accessToken->setClientId($client->getId());
307
+            $accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
308
+            $accessToken->setHashedCode(hash('sha512', $code));
309
+            $accessToken->setTokenId($generatedToken->getId());
310
+            $this->accessTokenMapper->insert($accessToken);
311 311
 
312
-			$redirectUri = sprintf(
313
-				'%s?state=%s&code=%s',
314
-				$client->getRedirectUri(),
315
-				urlencode($this->session->get('oauth.state')),
316
-				urlencode($code)
317
-			);
318
-			$this->session->remove('oauth.state');
319
-		} else {
320
-			$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
312
+            $redirectUri = sprintf(
313
+                '%s?state=%s&code=%s',
314
+                $client->getRedirectUri(),
315
+                urlencode($this->session->get('oauth.state')),
316
+                urlencode($code)
317
+            );
318
+            $this->session->remove('oauth.state');
319
+        } else {
320
+            $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
321 321
 
322
-			// Clear the token from the login here
323
-			$this->tokenProvider->invalidateToken($sessionId);
324
-		}
322
+            // Clear the token from the login here
323
+            $this->tokenProvider->invalidateToken($sessionId);
324
+        }
325 325
 
326
-		return new Http\RedirectResponse($redirectUri);
327
-	}
326
+        return new Http\RedirectResponse($redirectUri);
327
+    }
328 328
 
329
-	private function getServerPath(): string {
330
-		$serverPostfix = '';
329
+    private function getServerPath(): string {
330
+        $serverPostfix = '';
331 331
 
332
-		if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
333
-			$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
334
-		} else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
335
-			$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
336
-		}
332
+        if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
333
+            $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
334
+        } else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
335
+            $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
336
+        }
337 337
 
338
-		$protocol = $this->request->getServerProtocol();
338
+        $protocol = $this->request->getServerProtocol();
339 339
 
340
-		if ($protocol !== "https") {
341
-			$xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
342
-			$xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
343
-			if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
344
-				$protocol = 'https';
345
-			}
346
-		}
340
+        if ($protocol !== "https") {
341
+            $xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
342
+            $xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
343
+            if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
344
+                $protocol = 'https';
345
+            }
346
+        }
347 347
 
348
-		return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
349
-	}
348
+        return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
349
+    }
350 350
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 */
125 125
 	private function isValidToken($stateToken) {
126 126
 		$currentToken = $this->session->get(self::stateName);
127
-		if(!is_string($stateToken) || !is_string($currentToken)) {
127
+		if (!is_string($stateToken) || !is_string($currentToken)) {
128 128
 			return false;
129 129
 		}
130 130
 		return hash_equals($currentToken, $stateToken);
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	public function showAuthPickerPage($clientIdentifier = '') {
159 159
 		$clientName = $this->getClientName();
160 160
 		$client = null;
161
-		if($clientIdentifier !== '') {
161
+		if ($clientIdentifier !== '') {
162 162
 			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
163 163
 			$clientName = $client->getName();
164 164
 		}
@@ -215,13 +215,13 @@  discard block
 block discarded – undo
215 215
 	 */
216 216
 	public function grantPage($stateToken = '',
217 217
 								 $clientIdentifier = '') {
218
-		if(!$this->isValidToken($stateToken)) {
218
+		if (!$this->isValidToken($stateToken)) {
219 219
 			return $this->stateTokenForbiddenResponse();
220 220
 		}
221 221
 
222 222
 		$clientName = $this->getClientName();
223 223
 		$client = null;
224
-		if($clientIdentifier !== '') {
224
+		if ($clientIdentifier !== '') {
225 225
 			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
226 226
 			$clientName = $client->getName();
227 227
 		}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	 */
253 253
 	public function generateAppPassword($stateToken,
254 254
 										$clientIdentifier = '') {
255
-		if(!$this->isValidToken($stateToken)) {
255
+		if (!$this->isValidToken($stateToken)) {
256 256
 			$this->session->remove(self::stateName);
257 257
 			return $this->stateTokenForbiddenResponse();
258 258
 		}
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 
284 284
 		$clientName = $this->getClientName();
285 285
 		$client = false;
286
-		if($clientIdentifier !== '') {
286
+		if ($clientIdentifier !== '') {
287 287
 			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
288 288
 			$clientName = $client->getName();
289 289
 		}
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 			IToken::DO_NOT_REMEMBER
301 301
 		);
302 302
 
303
-		if($client) {
303
+		if ($client) {
304 304
 			$code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
305 305
 			$accessToken = new AccessToken();
306 306
 			$accessToken->setClientId($client->getId());
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 			);
318 318
 			$this->session->remove('oauth.state');
319 319
 		} else {
320
-			$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
320
+			$redirectUri = 'nc://login/server:'.$this->getServerPath().'&user:'.urlencode($loginName).'&password:'.urlencode($token);
321 321
 
322 322
 			// Clear the token from the login here
323 323
 			$this->tokenProvider->invalidateToken($sessionId);
@@ -345,6 +345,6 @@  discard block
 block discarded – undo
345 345
 			}
346 346
 		}
347 347
 
348
-		return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
348
+		return $protocol."://".$this->request->getServerHost().$serverPostfix;
349 349
 	}
350 350
 }
Please login to merge, or discard this patch.
core/routes.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -36,51 +36,51 @@  discard block
 block discarded – undo
36 36
 
37 37
 $application = new Application();
38 38
 $application->registerRoutes($this, [
39
-	'routes' => [
40
-		['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
41
-		['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'],
42
-		['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
43
-		['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
44
-		['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
45
-		['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
46
-		['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
47
-		['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
48
-		['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
49
-		['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'],
50
-		['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
51
-		['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
52
-		['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
53
-		['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
54
-		['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'],
55
-		['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'],
56
-		['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'],
57
-		['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
58
-		['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
59
-		['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
60
-		['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
61
-		['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
62
-		['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
63
-		['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}', 'verb' => 'GET'],
64
-		['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}', 'verb' => 'GET'],
65
-		['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
66
-		['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
67
-		['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
68
-		['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'],
69
-		['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'],
70
-		['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'],
71
-	],
72
-	'ocs' => [
73
-		['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
74
-		['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
75
-		['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
76
-		['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
77
-		['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
78
-		['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
79
-		['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'],
80
-		['root' => '/core', 'name' => 'WhatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'],
81
-		['root' => '/core', 'name' => 'WhatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'],
82
-		['root' => '/core', 'name' => 'AppPassword#getAppPassword', 'url' => '/getapppassword', 'verb' => 'GET'],
83
-	],
39
+    'routes' => [
40
+        ['name' => 'lost#email', 'url' => '/lostpassword/email', 'verb' => 'POST'],
41
+        ['name' => 'lost#resetform', 'url' => '/lostpassword/reset/form/{token}/{userId}', 'verb' => 'GET'],
42
+        ['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
43
+        ['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
44
+        ['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
45
+        ['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
46
+        ['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
47
+        ['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
48
+        ['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
49
+        ['name' => 'CSRFToken#index', 'url' => '/csrftoken', 'verb' => 'GET'],
50
+        ['name' => 'login#tryLogin', 'url' => '/login', 'verb' => 'POST'],
51
+        ['name' => 'login#confirmPassword', 'url' => '/login/confirm', 'verb' => 'POST'],
52
+        ['name' => 'login#showLoginForm', 'url' => '/login', 'verb' => 'GET'],
53
+        ['name' => 'login#logout', 'url' => '/logout', 'verb' => 'GET'],
54
+        ['name' => 'ClientFlowLogin#showAuthPickerPage', 'url' => '/login/flow', 'verb' => 'GET'],
55
+        ['name' => 'ClientFlowLogin#generateAppPassword', 'url' => '/login/flow', 'verb' => 'POST'],
56
+        ['name' => 'ClientFlowLogin#grantPage', 'url' => '/login/flow/grant', 'verb' => 'GET'],
57
+        ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
58
+        ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
59
+        ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
60
+        ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
61
+        ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
62
+        ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
63
+        ['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}', 'verb' => 'GET'],
64
+        ['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}', 'verb' => 'GET'],
65
+        ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
66
+        ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
67
+        ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
68
+        ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'],
69
+        ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'],
70
+        ['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'],
71
+    ],
72
+    'ocs' => [
73
+        ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
74
+        ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
75
+        ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
76
+        ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
77
+        ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
78
+        ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
79
+        ['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'],
80
+        ['root' => '/core', 'name' => 'WhatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'],
81
+        ['root' => '/core', 'name' => 'WhatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'],
82
+        ['root' => '/core', 'name' => 'AppPassword#getAppPassword', 'url' => '/getapppassword', 'verb' => 'GET'],
83
+    ],
84 84
 ]);
85 85
 
86 86
 // Post installation check
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
 // Core ajax actions
90 90
 // Routing
91 91
 $this->create('core_ajax_update', '/core/ajax/update.php')
92
-	->actionInclude('core/ajax/update.php');
92
+    ->actionInclude('core/ajax/update.php');
93 93
 
94 94
 // File routes
95 95
 $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) {
96
-	$app = new \OCA\Files\AppInfo\Application($urlParams);
97
-	$app->dispatch('ViewController', 'index');
96
+    $app = new \OCA\Files\AppInfo\Application($urlParams);
97
+    $app->dispatch('ViewController', 'index');
98 98
 });
99 99
 
100 100
 // Call routes
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
  * @suppress PhanUndeclaredClassMethod
104 104
  */
105 105
 $this->create('spreed.pagecontroller.showCall', '/call/{token}')->action(function($urlParams) {
106
-	if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) {
107
-		$app = new \OCA\Spreed\AppInfo\Application($urlParams);
108
-		$app->dispatch('PageController', 'index');
109
-	} else {
110
-		throw new \OC\HintException('App spreed is not enabled');
111
-	}
106
+    if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) {
107
+        $app = new \OCA\Spreed\AppInfo\Application($urlParams);
108
+        $app->dispatch('PageController', 'index');
109
+    } else {
110
+        throw new \OC\HintException('App spreed is not enabled');
111
+    }
112 112
 });
113 113
 
114 114
 // OCM routes
@@ -117,12 +117,12 @@  discard block
 block discarded – undo
117 117
  * @suppress PhanUndeclaredClassMethod
118 118
  */
119 119
 $this->create('cloud_federation_api.requesthandlercontroller.addShare', '/ocm/shares')->post()->action(function($urlParams) {
120
-	if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) {
121
-		$app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams);
122
-		$app->dispatch('RequestHandlerController', 'addShare');
123
-	} else {
124
-		throw new \OC\HintException('Cloud Federation API not enabled');
125
-	}
120
+    if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) {
121
+        $app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams);
122
+        $app->dispatch('RequestHandlerController', 'addShare');
123
+    } else {
124
+        throw new \OC\HintException('Cloud Federation API not enabled');
125
+    }
126 126
 });
127 127
 
128 128
 /**
@@ -130,53 +130,53 @@  discard block
 block discarded – undo
130 130
  * @suppress PhanUndeclaredClassMethod
131 131
  */
132 132
 $this->create('cloud_federation_api.requesthandlercontroller.receiveNotification', '/ocm/notifications')->post()->action(function($urlParams) {
133
-	if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) {
134
-		$app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams);
135
-		$app->dispatch('RequestHandlerController', 'receiveNotification');
136
-	} else {
137
-		throw new \OC\HintException('Cloud Federation API not enabled');
138
-	}
133
+    if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) {
134
+        $app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams);
135
+        $app->dispatch('RequestHandlerController', 'receiveNotification');
136
+    } else {
137
+        throw new \OC\HintException('Cloud Federation API not enabled');
138
+    }
139 139
 });
140 140
 
141 141
 
142 142
 // Sharing routes
143 143
 $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) {
144
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
145
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
146
-		$app->dispatch('ShareController', 'showShare');
147
-	} else {
148
-		throw new \OC\HintException('App file sharing is not enabled');
149
-	}
144
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
145
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
146
+        $app->dispatch('ShareController', 'showShare');
147
+    } else {
148
+        throw new \OC\HintException('App file sharing is not enabled');
149
+    }
150 150
 });
151 151
 $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate/{redirect}')->post()->action(function($urlParams) {
152
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
153
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
154
-		$app->dispatch('ShareController', 'authenticate');
155
-	} else {
156
-		throw new \OC\HintException('App file sharing is not enabled');
157
-	}
152
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
153
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
154
+        $app->dispatch('ShareController', 'authenticate');
155
+    } else {
156
+        throw new \OC\HintException('App file sharing is not enabled');
157
+    }
158 158
 });
159 159
 $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate/{redirect}')->get()->action(function($urlParams) {
160
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
161
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
162
-		$app->dispatch('ShareController', 'showAuthenticate');
163
-	} else {
164
-		throw new \OC\HintException('App file sharing is not enabled');
165
-	}
160
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
161
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
162
+        $app->dispatch('ShareController', 'showAuthenticate');
163
+    } else {
164
+        throw new \OC\HintException('App file sharing is not enabled');
165
+    }
166 166
 });
167 167
 $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) {
168
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
169
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
170
-		$app->dispatch('ShareController', 'downloadShare');
171
-	} else {
172
-		throw new \OC\HintException('App file sharing is not enabled');
173
-	}
168
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
169
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
170
+        $app->dispatch('ShareController', 'downloadShare');
171
+    } else {
172
+        throw new \OC\HintException('App file sharing is not enabled');
173
+    }
174 174
 });
175 175
 $this->create('files_sharing.publicpreview.directLink', '/s/{token}/preview')->get()->action(function($urlParams) {
176
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
177
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
178
-		$app->dispatch('PublicPreviewController', 'directLink');
179
-	} else {
180
-		throw new \OC\HintException('App file sharing is not enabled');
181
-	}
176
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
177
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
178
+        $app->dispatch('PublicPreviewController', 'directLink');
179
+    } else {
180
+        throw new \OC\HintException('App file sharing is not enabled');
181
+    }
182 182
 });
Please login to merge, or discard this patch.