Passed
Push — master ( 40e3a7...076f6b )
by Morris
10:24
created
core/templates/loginflow/authpicker.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	<h2><?php p($l->t('Connect to your account')) ?></h2>
32 32
 	<p class="info">
33 33
 		<?php print_unescaped($l->t('Please log in before granting %1$s access to your %2$s account.', [
34
-								'<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>',
34
+								'<strong>'.\OCP\Util::sanitizeHTML($_['client']).'</strong>',
35 35
 								\OCP\Util::sanitizeHTML($_['instanceName'])
36 36
 							])) ?>
37 37
 	</p>
@@ -59,6 +59,6 @@  discard block
 block discarded – undo
59 59
 	</form>
60 60
 </div>
61 61
 
62
-<?php if(empty($_['oauthState'])): ?>
62
+<?php if (empty($_['oauthState'])): ?>
63 63
 <a id="app-token-login" class="warning" href="#"><?php p($l->t('Alternative log in using app token')) ?></a>
64 64
 <?php endif; ?>
Please login to merge, or discard this patch.
core/routes.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -36,52 +36,52 @@  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' => 'ClientFlowLogin#apptokenRedirect', 'url' => '/login/flow/apptoken', 'verb' => 'POST'],
58
-		['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
59
-		['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
60
-		['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
61
-		['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
62
-		['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
63
-		['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
64
-		['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}', 'verb' => 'GET'],
65
-		['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}', 'verb' => 'GET'],
66
-		['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
67
-		['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
68
-		['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
69
-		['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'],
70
-		['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'],
71
-		['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'],
72
-	],
73
-	'ocs' => [
74
-		['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
75
-		['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
76
-		['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
77
-		['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
78
-		['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
79
-		['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
80
-		['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'],
81
-		['root' => '/core', 'name' => 'WhatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'],
82
-		['root' => '/core', 'name' => 'WhatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'],
83
-		['root' => '/core', 'name' => 'AppPassword#getAppPassword', 'url' => '/getapppassword', 'verb' => 'GET'],
84
-	],
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' => 'ClientFlowLogin#apptokenRedirect', 'url' => '/login/flow/apptoken', 'verb' => 'POST'],
58
+        ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'],
59
+        ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'],
60
+        ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'],
61
+        ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'],
62
+        ['name' => 'Preview#getPreviewByFileId', 'url' => '/core/preview', 'verb' => 'GET'],
63
+        ['name' => 'Preview#getPreview', 'url' => '/core/preview.png', 'verb' => 'GET'],
64
+        ['name' => 'Svg#getSvgFromCore', 'url' => '/svg/core/{folder}/{fileName}', 'verb' => 'GET'],
65
+        ['name' => 'Svg#getSvgFromApp', 'url' => '/svg/{app}/{fileName}', 'verb' => 'GET'],
66
+        ['name' => 'Css#getCss', 'url' => '/css/{appName}/{fileName}', 'verb' => 'GET'],
67
+        ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'],
68
+        ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'],
69
+        ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'],
70
+        ['name' => 'WalledGarden#get', 'url' => '/204', 'verb' => 'GET'],
71
+        ['name' => 'Search#search', 'url' => '/core/search', 'verb' => 'GET'],
72
+    ],
73
+    'ocs' => [
74
+        ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'],
75
+        ['root' => '', 'name' => 'OCS#getConfig', 'url' => '/config', 'verb' => 'GET'],
76
+        ['root' => '/person', 'name' => 'OCS#personCheck', 'url' => '/check', 'verb' => 'POST'],
77
+        ['root' => '/identityproof', 'name' => 'OCS#getIdentityProof', 'url' => '/key/{cloudId}', 'verb' => 'GET'],
78
+        ['root' => '/core', 'name' => 'Navigation#getAppsNavigation', 'url' => '/navigation/apps', 'verb' => 'GET'],
79
+        ['root' => '/core', 'name' => 'Navigation#getSettingsNavigation', 'url' => '/navigation/settings', 'verb' => 'GET'],
80
+        ['root' => '/core', 'name' => 'AutoComplete#get', 'url' => '/autocomplete/get', 'verb' => 'GET'],
81
+        ['root' => '/core', 'name' => 'WhatsNew#get', 'url' => '/whatsnew', 'verb' => 'GET'],
82
+        ['root' => '/core', 'name' => 'WhatsNew#dismiss', 'url' => '/whatsnew', 'verb' => 'POST'],
83
+        ['root' => '/core', 'name' => 'AppPassword#getAppPassword', 'url' => '/getapppassword', 'verb' => 'GET'],
84
+    ],
85 85
 ]);
86 86
 
87 87
 // Post installation check
@@ -90,12 +90,12 @@  discard block
 block discarded – undo
90 90
 // Core ajax actions
91 91
 // Routing
92 92
 $this->create('core_ajax_update', '/core/ajax/update.php')
93
-	->actionInclude('core/ajax/update.php');
93
+    ->actionInclude('core/ajax/update.php');
94 94
 
95 95
 // File routes
96 96
 $this->create('files.viewcontroller.showFile', '/f/{fileid}')->action(function($urlParams) {
97
-	$app = new \OCA\Files\AppInfo\Application($urlParams);
98
-	$app->dispatch('ViewController', 'index');
97
+    $app = new \OCA\Files\AppInfo\Application($urlParams);
98
+    $app->dispatch('ViewController', 'index');
99 99
 });
100 100
 
101 101
 // Call routes
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
  * @suppress PhanUndeclaredClassMethod
105 105
  */
106 106
 $this->create('spreed.pagecontroller.showCall', '/call/{token}')->action(function($urlParams) {
107
-	if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) {
108
-		$app = new \OCA\Spreed\AppInfo\Application($urlParams);
109
-		$app->dispatch('PageController', 'index');
110
-	} else {
111
-		throw new \OC\HintException('App spreed is not enabled');
112
-	}
107
+    if (class_exists(\OCA\Spreed\AppInfo\Application::class, false)) {
108
+        $app = new \OCA\Spreed\AppInfo\Application($urlParams);
109
+        $app->dispatch('PageController', 'index');
110
+    } else {
111
+        throw new \OC\HintException('App spreed is not enabled');
112
+    }
113 113
 });
114 114
 
115 115
 // OCM routes
@@ -118,12 +118,12 @@  discard block
 block discarded – undo
118 118
  * @suppress PhanUndeclaredClassMethod
119 119
  */
120 120
 $this->create('cloud_federation_api.requesthandlercontroller.addShare', '/ocm/shares')->post()->action(function($urlParams) {
121
-	if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) {
122
-		$app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams);
123
-		$app->dispatch('RequestHandlerController', 'addShare');
124
-	} else {
125
-		throw new \OC\HintException('Cloud Federation API not enabled');
126
-	}
121
+    if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) {
122
+        $app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams);
123
+        $app->dispatch('RequestHandlerController', 'addShare');
124
+    } else {
125
+        throw new \OC\HintException('Cloud Federation API not enabled');
126
+    }
127 127
 });
128 128
 
129 129
 /**
@@ -131,53 +131,53 @@  discard block
 block discarded – undo
131 131
  * @suppress PhanUndeclaredClassMethod
132 132
  */
133 133
 $this->create('cloud_federation_api.requesthandlercontroller.receiveNotification', '/ocm/notifications')->post()->action(function($urlParams) {
134
-	if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) {
135
-		$app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams);
136
-		$app->dispatch('RequestHandlerController', 'receiveNotification');
137
-	} else {
138
-		throw new \OC\HintException('Cloud Federation API not enabled');
139
-	}
134
+    if (class_exists(\OCA\CloudFederationAPI\AppInfo\Application::class, false)) {
135
+        $app = new \OCA\CloudFederationAPI\AppInfo\Application($urlParams);
136
+        $app->dispatch('RequestHandlerController', 'receiveNotification');
137
+    } else {
138
+        throw new \OC\HintException('Cloud Federation API not enabled');
139
+    }
140 140
 });
141 141
 
142 142
 
143 143
 // Sharing routes
144 144
 $this->create('files_sharing.sharecontroller.showShare', '/s/{token}')->action(function($urlParams) {
145
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
146
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
147
-		$app->dispatch('ShareController', 'showShare');
148
-	} else {
149
-		throw new \OC\HintException('App file sharing is not enabled');
150
-	}
145
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
146
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
147
+        $app->dispatch('ShareController', 'showShare');
148
+    } else {
149
+        throw new \OC\HintException('App file sharing is not enabled');
150
+    }
151 151
 });
152 152
 $this->create('files_sharing.sharecontroller.authenticate', '/s/{token}/authenticate/{redirect}')->post()->action(function($urlParams) {
153
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
154
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
155
-		$app->dispatch('ShareController', 'authenticate');
156
-	} else {
157
-		throw new \OC\HintException('App file sharing is not enabled');
158
-	}
153
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
154
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
155
+        $app->dispatch('ShareController', 'authenticate');
156
+    } else {
157
+        throw new \OC\HintException('App file sharing is not enabled');
158
+    }
159 159
 });
160 160
 $this->create('files_sharing.sharecontroller.showAuthenticate', '/s/{token}/authenticate/{redirect}')->get()->action(function($urlParams) {
161
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
162
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
163
-		$app->dispatch('ShareController', 'showAuthenticate');
164
-	} else {
165
-		throw new \OC\HintException('App file sharing is not enabled');
166
-	}
161
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
162
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
163
+        $app->dispatch('ShareController', 'showAuthenticate');
164
+    } else {
165
+        throw new \OC\HintException('App file sharing is not enabled');
166
+    }
167 167
 });
168 168
 $this->create('files_sharing.sharecontroller.downloadShare', '/s/{token}/download')->get()->action(function($urlParams) {
169
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
170
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
171
-		$app->dispatch('ShareController', 'downloadShare');
172
-	} else {
173
-		throw new \OC\HintException('App file sharing is not enabled');
174
-	}
169
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
170
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
171
+        $app->dispatch('ShareController', 'downloadShare');
172
+    } else {
173
+        throw new \OC\HintException('App file sharing is not enabled');
174
+    }
175 175
 });
176 176
 $this->create('files_sharing.publicpreview.directLink', '/s/{token}/preview')->get()->action(function($urlParams) {
177
-	if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
178
-		$app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
179
-		$app->dispatch('PublicPreviewController', 'directLink');
180
-	} else {
181
-		throw new \OC\HintException('App file sharing is not enabled');
182
-	}
177
+    if (class_exists(\OCA\Files_Sharing\AppInfo\Application::class, false)) {
178
+        $app = new \OCA\Files_Sharing\AppInfo\Application($urlParams);
179
+        $app->dispatch('PublicPreviewController', 'directLink');
180
+    } else {
181
+        throw new \OC\HintException('App file sharing is not enabled');
182
+    }
183 183
 });
Please login to merge, or discard this patch.
core/Controller/ClientFlowLoginController.php 2 patches
Indentation   +312 added lines, -312 removed lines patch added patch discarded remove patch
@@ -48,316 +48,316 @@
 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
-	 * @NoSameSiteCookieRequired
211
-	 * @UseSession
212
-	 *
213
-	 * @param string $stateToken
214
-	 * @param string $clientIdentifier
215
-	 * @return TemplateResponse
216
-	 */
217
-	public function grantPage($stateToken = '',
218
-								 $clientIdentifier = '') {
219
-		if(!$this->isValidToken($stateToken)) {
220
-			return $this->stateTokenForbiddenResponse();
221
-		}
222
-
223
-		$clientName = $this->getClientName();
224
-		$client = null;
225
-		if($clientIdentifier !== '') {
226
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
227
-			$clientName = $client->getName();
228
-		}
229
-
230
-		return new TemplateResponse(
231
-			$this->appName,
232
-			'loginflow/grant',
233
-			[
234
-				'client' => $clientName,
235
-				'clientIdentifier' => $clientIdentifier,
236
-				'instanceName' => $this->defaults->getName(),
237
-				'urlGenerator' => $this->urlGenerator,
238
-				'stateToken' => $stateToken,
239
-				'serverHost' => $this->getServerPath(),
240
-				'oauthState' => $this->session->get('oauth.state'),
241
-			],
242
-			'guest'
243
-		);
244
-	}
245
-
246
-	/**
247
-	 * @NoAdminRequired
248
-	 * @UseSession
249
-	 *
250
-	 * @param string $stateToken
251
-	 * @param string $clientIdentifier
252
-	 * @return Http\RedirectResponse|Response
253
-	 */
254
-	public function generateAppPassword($stateToken,
255
-										$clientIdentifier = '') {
256
-		if(!$this->isValidToken($stateToken)) {
257
-			$this->session->remove(self::stateName);
258
-			return $this->stateTokenForbiddenResponse();
259
-		}
260
-
261
-		$this->session->remove(self::stateName);
262
-
263
-		try {
264
-			$sessionId = $this->session->getId();
265
-		} catch (SessionNotAvailableException $ex) {
266
-			$response = new Response();
267
-			$response->setStatus(Http::STATUS_FORBIDDEN);
268
-			return $response;
269
-		}
270
-
271
-		try {
272
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
273
-			$loginName = $sessionToken->getLoginName();
274
-			try {
275
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
276
-			} catch (PasswordlessTokenException $ex) {
277
-				$password = null;
278
-			}
279
-		} catch (InvalidTokenException $ex) {
280
-			$response = new Response();
281
-			$response->setStatus(Http::STATUS_FORBIDDEN);
282
-			return $response;
283
-		}
284
-
285
-		$clientName = $this->getClientName();
286
-		$client = false;
287
-		if($clientIdentifier !== '') {
288
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
289
-			$clientName = $client->getName();
290
-		}
291
-
292
-		$token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
293
-		$uid = $this->userSession->getUser()->getUID();
294
-		$generatedToken = $this->tokenProvider->generateToken(
295
-			$token,
296
-			$uid,
297
-			$loginName,
298
-			$password,
299
-			$clientName,
300
-			IToken::PERMANENT_TOKEN,
301
-			IToken::DO_NOT_REMEMBER
302
-		);
303
-
304
-		if($client) {
305
-			$code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
306
-			$accessToken = new AccessToken();
307
-			$accessToken->setClientId($client->getId());
308
-			$accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
309
-			$accessToken->setHashedCode(hash('sha512', $code));
310
-			$accessToken->setTokenId($generatedToken->getId());
311
-			$this->accessTokenMapper->insert($accessToken);
312
-
313
-			$redirectUri = sprintf(
314
-				'%s?state=%s&code=%s',
315
-				$client->getRedirectUri(),
316
-				urlencode($this->session->get('oauth.state')),
317
-				urlencode($code)
318
-			);
319
-			$this->session->remove('oauth.state');
320
-		} else {
321
-			$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
322
-
323
-			// Clear the token from the login here
324
-			$this->tokenProvider->invalidateToken($sessionId);
325
-		}
326
-
327
-		return new Http\RedirectResponse($redirectUri);
328
-	}
329
-
330
-	/**
331
-	 * @PublicPage
332
-	 */
333
-	public function apptokenRedirect(string $stateToken, string $user, string $password) {
334
-		if (!$this->isValidToken($stateToken)) {
335
-			return $this->stateTokenForbiddenResponse();
336
-		}
337
-
338
-		$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);
339
-		return new Http\RedirectResponse($redirectUri);
340
-	}
341
-
342
-	private function getServerPath(): string {
343
-		$serverPostfix = '';
344
-
345
-		if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
346
-			$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
347
-		} else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
348
-			$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
349
-		}
350
-
351
-		$protocol = $this->request->getServerProtocol();
352
-
353
-		if ($protocol !== "https") {
354
-			$xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
355
-			$xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
356
-			if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
357
-				$protocol = 'https';
358
-			}
359
-		}
360
-
361
-		return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
362
-	}
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
+     * @NoSameSiteCookieRequired
211
+     * @UseSession
212
+     *
213
+     * @param string $stateToken
214
+     * @param string $clientIdentifier
215
+     * @return TemplateResponse
216
+     */
217
+    public function grantPage($stateToken = '',
218
+                                    $clientIdentifier = '') {
219
+        if(!$this->isValidToken($stateToken)) {
220
+            return $this->stateTokenForbiddenResponse();
221
+        }
222
+
223
+        $clientName = $this->getClientName();
224
+        $client = null;
225
+        if($clientIdentifier !== '') {
226
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
227
+            $clientName = $client->getName();
228
+        }
229
+
230
+        return new TemplateResponse(
231
+            $this->appName,
232
+            'loginflow/grant',
233
+            [
234
+                'client' => $clientName,
235
+                'clientIdentifier' => $clientIdentifier,
236
+                'instanceName' => $this->defaults->getName(),
237
+                'urlGenerator' => $this->urlGenerator,
238
+                'stateToken' => $stateToken,
239
+                'serverHost' => $this->getServerPath(),
240
+                'oauthState' => $this->session->get('oauth.state'),
241
+            ],
242
+            'guest'
243
+        );
244
+    }
245
+
246
+    /**
247
+     * @NoAdminRequired
248
+     * @UseSession
249
+     *
250
+     * @param string $stateToken
251
+     * @param string $clientIdentifier
252
+     * @return Http\RedirectResponse|Response
253
+     */
254
+    public function generateAppPassword($stateToken,
255
+                                        $clientIdentifier = '') {
256
+        if(!$this->isValidToken($stateToken)) {
257
+            $this->session->remove(self::stateName);
258
+            return $this->stateTokenForbiddenResponse();
259
+        }
260
+
261
+        $this->session->remove(self::stateName);
262
+
263
+        try {
264
+            $sessionId = $this->session->getId();
265
+        } catch (SessionNotAvailableException $ex) {
266
+            $response = new Response();
267
+            $response->setStatus(Http::STATUS_FORBIDDEN);
268
+            return $response;
269
+        }
270
+
271
+        try {
272
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
273
+            $loginName = $sessionToken->getLoginName();
274
+            try {
275
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
276
+            } catch (PasswordlessTokenException $ex) {
277
+                $password = null;
278
+            }
279
+        } catch (InvalidTokenException $ex) {
280
+            $response = new Response();
281
+            $response->setStatus(Http::STATUS_FORBIDDEN);
282
+            return $response;
283
+        }
284
+
285
+        $clientName = $this->getClientName();
286
+        $client = false;
287
+        if($clientIdentifier !== '') {
288
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
289
+            $clientName = $client->getName();
290
+        }
291
+
292
+        $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
293
+        $uid = $this->userSession->getUser()->getUID();
294
+        $generatedToken = $this->tokenProvider->generateToken(
295
+            $token,
296
+            $uid,
297
+            $loginName,
298
+            $password,
299
+            $clientName,
300
+            IToken::PERMANENT_TOKEN,
301
+            IToken::DO_NOT_REMEMBER
302
+        );
303
+
304
+        if($client) {
305
+            $code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
306
+            $accessToken = new AccessToken();
307
+            $accessToken->setClientId($client->getId());
308
+            $accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
309
+            $accessToken->setHashedCode(hash('sha512', $code));
310
+            $accessToken->setTokenId($generatedToken->getId());
311
+            $this->accessTokenMapper->insert($accessToken);
312
+
313
+            $redirectUri = sprintf(
314
+                '%s?state=%s&code=%s',
315
+                $client->getRedirectUri(),
316
+                urlencode($this->session->get('oauth.state')),
317
+                urlencode($code)
318
+            );
319
+            $this->session->remove('oauth.state');
320
+        } else {
321
+            $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
322
+
323
+            // Clear the token from the login here
324
+            $this->tokenProvider->invalidateToken($sessionId);
325
+        }
326
+
327
+        return new Http\RedirectResponse($redirectUri);
328
+    }
329
+
330
+    /**
331
+     * @PublicPage
332
+     */
333
+    public function apptokenRedirect(string $stateToken, string $user, string $password) {
334
+        if (!$this->isValidToken($stateToken)) {
335
+            return $this->stateTokenForbiddenResponse();
336
+        }
337
+
338
+        $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);
339
+        return new Http\RedirectResponse($redirectUri);
340
+    }
341
+
342
+    private function getServerPath(): string {
343
+        $serverPostfix = '';
344
+
345
+        if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
346
+            $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
347
+        } else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
348
+            $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
349
+        }
350
+
351
+        $protocol = $this->request->getServerProtocol();
352
+
353
+        if ($protocol !== "https") {
354
+            $xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
355
+            $xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
356
+            if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
357
+                $protocol = 'https';
358
+            }
359
+        }
360
+
361
+        return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
362
+    }
363 363
 }
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
 		}
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
 	 */
217 217
 	public function grantPage($stateToken = '',
218 218
 								 $clientIdentifier = '') {
219
-		if(!$this->isValidToken($stateToken)) {
219
+		if (!$this->isValidToken($stateToken)) {
220 220
 			return $this->stateTokenForbiddenResponse();
221 221
 		}
222 222
 
223 223
 		$clientName = $this->getClientName();
224 224
 		$client = null;
225
-		if($clientIdentifier !== '') {
225
+		if ($clientIdentifier !== '') {
226 226
 			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
227 227
 			$clientName = $client->getName();
228 228
 		}
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 */
254 254
 	public function generateAppPassword($stateToken,
255 255
 										$clientIdentifier = '') {
256
-		if(!$this->isValidToken($stateToken)) {
256
+		if (!$this->isValidToken($stateToken)) {
257 257
 			$this->session->remove(self::stateName);
258 258
 			return $this->stateTokenForbiddenResponse();
259 259
 		}
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 
285 285
 		$clientName = $this->getClientName();
286 286
 		$client = false;
287
-		if($clientIdentifier !== '') {
287
+		if ($clientIdentifier !== '') {
288 288
 			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
289 289
 			$clientName = $client->getName();
290 290
 		}
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 			IToken::DO_NOT_REMEMBER
302 302
 		);
303 303
 
304
-		if($client) {
304
+		if ($client) {
305 305
 			$code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
306 306
 			$accessToken = new AccessToken();
307 307
 			$accessToken->setClientId($client->getId());
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 			);
319 319
 			$this->session->remove('oauth.state');
320 320
 		} else {
321
-			$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
321
+			$redirectUri = 'nc://login/server:'.$this->getServerPath().'&user:'.urlencode($loginName).'&password:'.urlencode($token);
322 322
 
323 323
 			// Clear the token from the login here
324 324
 			$this->tokenProvider->invalidateToken($sessionId);
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 			return $this->stateTokenForbiddenResponse();
336 336
 		}
337 337
 
338
-		$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);
338
+		$redirectUri = 'nc://login/server:'.$this->getServerPath().'&user:'.urlencode($user).'&password:'.urlencode($password);
339 339
 		return new Http\RedirectResponse($redirectUri);
340 340
 	}
341 341
 
@@ -358,6 +358,6 @@  discard block
 block discarded – undo
358 358
 			}
359 359
 		}
360 360
 
361
-		return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
361
+		return $protocol."://".$this->request->getServerHost().$serverPostfix;
362 362
 	}
363 363
 }
Please login to merge, or discard this patch.