Passed
Push — master ( d836b8...0f08f3 )
by Morris
12:51
created
core/Controller/ClientFlowLoginController.php 2 patches
Indentation   +327 added lines, -327 removed lines patch added patch discarded remove patch
@@ -48,331 +48,331 @@
 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;
71
-
72
-	const stateName = 'client.flow.state.token';
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
-	}
112
-
113
-	/**
114
-	 * @return string
115
-	 */
116
-	private function getClientName() {
117
-		$userAgent = $this->request->getHeader('USER_AGENT');
118
-		return $userAgent !== '' ? $userAgent : 'unknown';
119
-	}
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
-	}
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
-	}
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
-		}
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
-		}
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);
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
-	}
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
-		}
221
-
222
-		$clientName = $this->getClientName();
223
-		$client = null;
224
-		if($clientIdentifier !== '') {
225
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
226
-			$clientName = $client->getName();
227
-		}
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
-	}
244
-
245
-	/**
246
-	 * @NoAdminRequired
247
-	 * @NoCSRFRequired
248
-	 * @UseSession
249
-	 *
250
-	 * @param string $stateToken
251
-	 * @param string $clientIdentifier
252
-	 * @return TemplateResponse
253
-	 */
254
-	public function redirectPage($stateToken = '',
255
-								 $clientIdentifier = '') {
256
-		if(!$this->isValidToken($stateToken)) {
257
-			return $this->stateTokenForbiddenResponse();
258
-		}
259
-
260
-		return new TemplateResponse(
261
-			$this->appName,
262
-			'loginflow/redirect',
263
-			[
264
-				'urlGenerator' => $this->urlGenerator,
265
-				'stateToken' => $stateToken,
266
-				'clientIdentifier' => $clientIdentifier,
267
-				'oauthState' => $this->session->get('oauth.state'),
268
-			],
269
-			'guest'
270
-		);
271
-	}
272
-
273
-	/**
274
-	 * @NoAdminRequired
275
-	 * @UseSession
276
-	 *
277
-	 * @param string $stateToken
278
-	 * @param string $clientIdentifier
279
-	 * @return Http\RedirectResponse|Response
280
-	 */
281
-	public function generateAppPassword($stateToken,
282
-										$clientIdentifier = '') {
283
-		if(!$this->isValidToken($stateToken)) {
284
-			$this->session->remove(self::stateName);
285
-			return $this->stateTokenForbiddenResponse();
286
-		}
287
-
288
-		$this->session->remove(self::stateName);
289
-
290
-		try {
291
-			$sessionId = $this->session->getId();
292
-		} catch (SessionNotAvailableException $ex) {
293
-			$response = new Response();
294
-			$response->setStatus(Http::STATUS_FORBIDDEN);
295
-			return $response;
296
-		}
297
-
298
-		try {
299
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
300
-			$loginName = $sessionToken->getLoginName();
301
-			try {
302
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
303
-			} catch (PasswordlessTokenException $ex) {
304
-				$password = null;
305
-			}
306
-		} catch (InvalidTokenException $ex) {
307
-			$response = new Response();
308
-			$response->setStatus(Http::STATUS_FORBIDDEN);
309
-			return $response;
310
-		}
311
-
312
-		$clientName = $this->getClientName();
313
-		$client = false;
314
-		if($clientIdentifier !== '') {
315
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
316
-			$clientName = $client->getName();
317
-		}
318
-
319
-		$token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
320
-		$uid = $this->userSession->getUser()->getUID();
321
-		$generatedToken = $this->tokenProvider->generateToken(
322
-			$token,
323
-			$uid,
324
-			$loginName,
325
-			$password,
326
-			$clientName,
327
-			IToken::PERMANENT_TOKEN,
328
-			IToken::DO_NOT_REMEMBER
329
-		);
330
-
331
-		if($client) {
332
-			$code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
333
-			$accessToken = new AccessToken();
334
-			$accessToken->setClientId($client->getId());
335
-			$accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
336
-			$accessToken->setHashedCode(hash('sha512', $code));
337
-			$accessToken->setTokenId($generatedToken->getId());
338
-			$this->accessTokenMapper->insert($accessToken);
339
-
340
-			$redirectUri = sprintf(
341
-				'%s?state=%s&code=%s',
342
-				$client->getRedirectUri(),
343
-				urlencode($this->session->get('oauth.state')),
344
-				urlencode($code)
345
-			);
346
-			$this->session->remove('oauth.state');
347
-		} else {
348
-			$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
349
-
350
-			// Clear the token from the login here
351
-			$this->tokenProvider->invalidateToken($sessionId);
352
-		}
353
-
354
-		return new Http\RedirectResponse($redirectUri);
355
-	}
356
-
357
-	private function getServerPath(): string {
358
-		$serverPostfix = '';
359
-
360
-		if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
361
-			$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
362
-		} else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
363
-			$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
364
-		}
365
-
366
-		$protocol = $this->request->getServerProtocol();
367
-
368
-		if ($protocol !== "https") {
369
-			$xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
370
-			$xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
371
-			if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
372
-				$protocol = 'https';
373
-			}
374
-		}
375
-
376
-		return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
377
-	}
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
+
72
+    const stateName = 'client.flow.state.token';
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
+    }
112
+
113
+    /**
114
+     * @return string
115
+     */
116
+    private function getClientName() {
117
+        $userAgent = $this->request->getHeader('USER_AGENT');
118
+        return $userAgent !== '' ? $userAgent : 'unknown';
119
+    }
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
+    }
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
+    }
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
+        }
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
+        }
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);
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
+    }
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
+        }
221
+
222
+        $clientName = $this->getClientName();
223
+        $client = null;
224
+        if($clientIdentifier !== '') {
225
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
226
+            $clientName = $client->getName();
227
+        }
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
+    }
244
+
245
+    /**
246
+     * @NoAdminRequired
247
+     * @NoCSRFRequired
248
+     * @UseSession
249
+     *
250
+     * @param string $stateToken
251
+     * @param string $clientIdentifier
252
+     * @return TemplateResponse
253
+     */
254
+    public function redirectPage($stateToken = '',
255
+                                    $clientIdentifier = '') {
256
+        if(!$this->isValidToken($stateToken)) {
257
+            return $this->stateTokenForbiddenResponse();
258
+        }
259
+
260
+        return new TemplateResponse(
261
+            $this->appName,
262
+            'loginflow/redirect',
263
+            [
264
+                'urlGenerator' => $this->urlGenerator,
265
+                'stateToken' => $stateToken,
266
+                'clientIdentifier' => $clientIdentifier,
267
+                'oauthState' => $this->session->get('oauth.state'),
268
+            ],
269
+            'guest'
270
+        );
271
+    }
272
+
273
+    /**
274
+     * @NoAdminRequired
275
+     * @UseSession
276
+     *
277
+     * @param string $stateToken
278
+     * @param string $clientIdentifier
279
+     * @return Http\RedirectResponse|Response
280
+     */
281
+    public function generateAppPassword($stateToken,
282
+                                        $clientIdentifier = '') {
283
+        if(!$this->isValidToken($stateToken)) {
284
+            $this->session->remove(self::stateName);
285
+            return $this->stateTokenForbiddenResponse();
286
+        }
287
+
288
+        $this->session->remove(self::stateName);
289
+
290
+        try {
291
+            $sessionId = $this->session->getId();
292
+        } catch (SessionNotAvailableException $ex) {
293
+            $response = new Response();
294
+            $response->setStatus(Http::STATUS_FORBIDDEN);
295
+            return $response;
296
+        }
297
+
298
+        try {
299
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
300
+            $loginName = $sessionToken->getLoginName();
301
+            try {
302
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
303
+            } catch (PasswordlessTokenException $ex) {
304
+                $password = null;
305
+            }
306
+        } catch (InvalidTokenException $ex) {
307
+            $response = new Response();
308
+            $response->setStatus(Http::STATUS_FORBIDDEN);
309
+            return $response;
310
+        }
311
+
312
+        $clientName = $this->getClientName();
313
+        $client = false;
314
+        if($clientIdentifier !== '') {
315
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
316
+            $clientName = $client->getName();
317
+        }
318
+
319
+        $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
320
+        $uid = $this->userSession->getUser()->getUID();
321
+        $generatedToken = $this->tokenProvider->generateToken(
322
+            $token,
323
+            $uid,
324
+            $loginName,
325
+            $password,
326
+            $clientName,
327
+            IToken::PERMANENT_TOKEN,
328
+            IToken::DO_NOT_REMEMBER
329
+        );
330
+
331
+        if($client) {
332
+            $code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
333
+            $accessToken = new AccessToken();
334
+            $accessToken->setClientId($client->getId());
335
+            $accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
336
+            $accessToken->setHashedCode(hash('sha512', $code));
337
+            $accessToken->setTokenId($generatedToken->getId());
338
+            $this->accessTokenMapper->insert($accessToken);
339
+
340
+            $redirectUri = sprintf(
341
+                '%s?state=%s&code=%s',
342
+                $client->getRedirectUri(),
343
+                urlencode($this->session->get('oauth.state')),
344
+                urlencode($code)
345
+            );
346
+            $this->session->remove('oauth.state');
347
+        } else {
348
+            $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
349
+
350
+            // Clear the token from the login here
351
+            $this->tokenProvider->invalidateToken($sessionId);
352
+        }
353
+
354
+        return new Http\RedirectResponse($redirectUri);
355
+    }
356
+
357
+    private function getServerPath(): string {
358
+        $serverPostfix = '';
359
+
360
+        if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
361
+            $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
362
+        } else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
363
+            $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
364
+        }
365
+
366
+        $protocol = $this->request->getServerProtocol();
367
+
368
+        if ($protocol !== "https") {
369
+            $xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
370
+            $xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
371
+            if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
372
+                $protocol = 'https';
373
+            }
374
+        }
375
+
376
+        return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
377
+    }
378 378
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 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
 		}
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 */
254 254
 	public function redirectPage($stateToken = '',
255 255
 								 $clientIdentifier = '') {
256
-		if(!$this->isValidToken($stateToken)) {
256
+		if (!$this->isValidToken($stateToken)) {
257 257
 			return $this->stateTokenForbiddenResponse();
258 258
 		}
259 259
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	 */
281 281
 	public function generateAppPassword($stateToken,
282 282
 										$clientIdentifier = '') {
283
-		if(!$this->isValidToken($stateToken)) {
283
+		if (!$this->isValidToken($stateToken)) {
284 284
 			$this->session->remove(self::stateName);
285 285
 			return $this->stateTokenForbiddenResponse();
286 286
 		}
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 
312 312
 		$clientName = $this->getClientName();
313 313
 		$client = false;
314
-		if($clientIdentifier !== '') {
314
+		if ($clientIdentifier !== '') {
315 315
 			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
316 316
 			$clientName = $client->getName();
317 317
 		}
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 			IToken::DO_NOT_REMEMBER
329 329
 		);
330 330
 
331
-		if($client) {
331
+		if ($client) {
332 332
 			$code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
333 333
 			$accessToken = new AccessToken();
334 334
 			$accessToken->setClientId($client->getId());
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 			);
346 346
 			$this->session->remove('oauth.state');
347 347
 		} else {
348
-			$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
348
+			$redirectUri = 'nc://login/server:'.$this->getServerPath().'&user:'.urlencode($loginName).'&password:'.urlencode($token);
349 349
 
350 350
 			// Clear the token from the login here
351 351
 			$this->tokenProvider->invalidateToken($sessionId);
@@ -373,6 +373,6 @@  discard block
 block discarded – undo
373 373
 			}
374 374
 		}
375 375
 
376
-		return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
376
+		return $protocol."://".$this->request->getServerHost().$serverPostfix;
377 377
 	}
378 378
 }
Please login to merge, or discard this patch.