Completed
Pull Request — master (#4704)
by Björn
15:19
created
core/templates/loginflow/authpicker.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,6 +54,6 @@
 block discarded – undo
54 54
 	</fieldset>
55 55
 </div>
56 56
 
57
-<?php if(empty($_['oauthState'])): ?>
57
+<?php if (empty($_['oauthState'])): ?>
58 58
 <a id="app-token-login" class="warning" href="#"><?php p($l->t('Alternative login using app token')) ?></a>
59 59
 <?php endif; ?>
Please login to merge, or discard this patch.
apps/oauth2/appinfo/routes.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -20,26 +20,26 @@
 block discarded – undo
20 20
  */
21 21
 
22 22
 return [
23
-	'routes' => [
24
-		[
25
-			'name' => 'Settings#addClient',
26
-			'url' => '/settings',
27
-			'verb' => 'POST',
28
-		],
29
-		[
30
-			'name' => 'Settings#deleteClient',
31
-			'url' => '/clients/{id}/delete',
32
-			'verb' => 'POST'
33
-		],
34
-		[
35
-			'name' => 'LoginRedirector#authorize',
36
-			'url' => '/authorize',
37
-			'verb' => 'GET',
38
-		],
39
-		[
40
-			'name' => 'OauthApi#getToken',
41
-			'url' => '/api/v1/token',
42
-			'verb' => 'POST'
43
-		],
44
-	],
23
+    'routes' => [
24
+        [
25
+            'name' => 'Settings#addClient',
26
+            'url' => '/settings',
27
+            'verb' => 'POST',
28
+        ],
29
+        [
30
+            'name' => 'Settings#deleteClient',
31
+            'url' => '/clients/{id}/delete',
32
+            'verb' => 'POST'
33
+        ],
34
+        [
35
+            'name' => 'LoginRedirector#authorize',
36
+            'url' => '/authorize',
37
+            'verb' => 'GET',
38
+        ],
39
+        [
40
+            'name' => 'OauthApi#getToken',
41
+            'url' => '/api/v1/token',
42
+            'verb' => 'POST'
43
+        ],
44
+    ],
45 45
 ];
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
apps/oauth2/lib/Db/Client.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,20 +34,20 @@
 block discarded – undo
34 34
  * @method void setName(string $name)
35 35
  */
36 36
 class Client extends Entity {
37
-	/** @var string */
38
-	protected $name;
39
-	/** @var string */
40
-	protected $redirectUri;
41
-	/** @var string */
42
-	protected $clientIdentifier;
43
-	/** @var string */
44
-	protected $secret;
37
+    /** @var string */
38
+    protected $name;
39
+    /** @var string */
40
+    protected $redirectUri;
41
+    /** @var string */
42
+    protected $clientIdentifier;
43
+    /** @var string */
44
+    protected $secret;
45 45
 
46
-	public function __construct() {
47
-		$this->addType('id', 'int');
48
-		$this->addType('name', 'string');
49
-		$this->addType('redirect_uri', 'string');
50
-		$this->addType('client_identifier', 'string');
51
-		$this->addType('secret', 'string');
52
-	}
46
+    public function __construct() {
47
+        $this->addType('id', 'int');
48
+        $this->addType('name', 'string');
49
+        $this->addType('redirect_uri', 'string');
50
+        $this->addType('client_identifier', 'string');
51
+        $this->addType('secret', 'string');
52
+    }
53 53
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Db/AccessToken.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,20 +34,20 @@
 block discarded – undo
34 34
  * @method void setHashedCode(string $token)
35 35
  */
36 36
 class AccessToken extends Entity {
37
-	/** @var int */
38
-	protected $tokenId;
39
-	/** @var int */
40
-	protected $clientId;
41
-	/** @var string */
42
-	protected $hashedCode;
43
-	/** @var string */
44
-	protected $encryptedToken;
37
+    /** @var int */
38
+    protected $tokenId;
39
+    /** @var int */
40
+    protected $clientId;
41
+    /** @var string */
42
+    protected $hashedCode;
43
+    /** @var string */
44
+    protected $encryptedToken;
45 45
 
46
-	public function __construct() {
47
-		$this->addType('id', 'int');
48
-		$this->addType('token_id', 'int');
49
-		$this->addType('client_id', 'int');
50
-		$this->addType('hashed_code', 'string');
51
-		$this->addType('encrypted_token', 'string');
52
-	}
46
+    public function __construct() {
47
+        $this->addType('id', 'int');
48
+        $this->addType('token_id', 'int');
49
+        $this->addType('client_id', 'int');
50
+        $this->addType('hashed_code', 'string');
51
+        $this->addType('encrypted_token', 'string');
52
+    }
53 53
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Controller/LoginRedirectorController.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -28,51 +28,51 @@
 block discarded – undo
28 28
 use OCP\IURLGenerator;
29 29
 
30 30
 class LoginRedirectorController extends Controller {
31
-	/** @var IURLGenerator */
32
-	private $urlGenerator;
33
-	/** @var ClientMapper */
34
-	private $clientMapper;
31
+    /** @var IURLGenerator */
32
+    private $urlGenerator;
33
+    /** @var ClientMapper */
34
+    private $clientMapper;
35 35
 
36
-	/**
37
-	 * @param string $appName
38
-	 * @param IRequest $request
39
-	 * @param IURLGenerator $urlGenerator
40
-	 * @param ClientMapper $clientMapper
41
-	 */
42
-	public function __construct($appName,
43
-								IRequest $request,
44
-								IURLGenerator $urlGenerator,
45
-								ClientMapper $clientMapper) {
46
-		parent::__construct($appName, $request);
47
-		$this->urlGenerator = $urlGenerator;
48
-		$this->clientMapper = $clientMapper;
49
-	}
36
+    /**
37
+     * @param string $appName
38
+     * @param IRequest $request
39
+     * @param IURLGenerator $urlGenerator
40
+     * @param ClientMapper $clientMapper
41
+     */
42
+    public function __construct($appName,
43
+                                IRequest $request,
44
+                                IURLGenerator $urlGenerator,
45
+                                ClientMapper $clientMapper) {
46
+        parent::__construct($appName, $request);
47
+        $this->urlGenerator = $urlGenerator;
48
+        $this->clientMapper = $clientMapper;
49
+    }
50 50
 
51
-	/**
52
-	 * @PublicPage
53
-	 * @NoCSRFRequired
54
-	 *
55
-	 * @param string $client_id
56
-	 * @param string $redirect_uri
57
-	 * @param string $state
58
-	 * @return RedirectResponse
59
-	 */
60
-	public function authorize($client_id,
61
-							  $redirect_uri,
62
-							  $state) {
63
-		$client = $this->clientMapper->getByIdentifier($client_id);
51
+    /**
52
+     * @PublicPage
53
+     * @NoCSRFRequired
54
+     *
55
+     * @param string $client_id
56
+     * @param string $redirect_uri
57
+     * @param string $state
58
+     * @return RedirectResponse
59
+     */
60
+    public function authorize($client_id,
61
+                                $redirect_uri,
62
+                                $state) {
63
+        $client = $this->clientMapper->getByIdentifier($client_id);
64 64
 
65
-		if($client->getRedirectUri() !== $redirect_uri) {
66
-			throw new \Exception('Redirect URI does not match');
67
-		}
65
+        if($client->getRedirectUri() !== $redirect_uri) {
66
+            throw new \Exception('Redirect URI does not match');
67
+        }
68 68
 
69
-		$targetUrl = $this->urlGenerator->linkToRouteAbsolute(
70
-			'core.ClientFlowLogin.showAuthPickerPage',
71
-			[
72
-				'clientIdentifier' => $client->getClientIdentifier(),
73
-				'oauthState' => $state,
74
-			]
75
-		);
76
-		return new RedirectResponse($targetUrl);
77
-	}
69
+        $targetUrl = $this->urlGenerator->linkToRouteAbsolute(
70
+            'core.ClientFlowLogin.showAuthPickerPage',
71
+            [
72
+                'clientIdentifier' => $client->getClientIdentifier(),
73
+                'oauthState' => $state,
74
+            ]
75
+        );
76
+        return new RedirectResponse($targetUrl);
77
+    }
78 78
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
 							  $state) {
63 63
 		$client = $this->clientMapper->getByIdentifier($client_id);
64 64
 
65
-		if($client->getRedirectUri() !== $redirect_uri) {
65
+		if ($client->getRedirectUri() !== $redirect_uri) {
66 66
 			throw new \Exception('Redirect URI does not match');
67 67
 		}
68 68
 
Please login to merge, or discard this patch.
apps/oauth2/lib/Controller/OauthApiController.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -30,59 +30,59 @@
 block discarded – undo
30 30
 use OCP\Security\ISecureRandom;
31 31
 
32 32
 class OauthApiController extends Controller {
33
-	/** @var AccessTokenMapper */
34
-	private $accessTokenMapper;
35
-	/** @var ICrypto */
36
-	private $crypto;
37
-	/** @var DefaultTokenMapper */
38
-	private $defaultTokenMapper;
39
-	/** @var ISecureRandom */
40
-	private $secureRandom;
33
+    /** @var AccessTokenMapper */
34
+    private $accessTokenMapper;
35
+    /** @var ICrypto */
36
+    private $crypto;
37
+    /** @var DefaultTokenMapper */
38
+    private $defaultTokenMapper;
39
+    /** @var ISecureRandom */
40
+    private $secureRandom;
41 41
 
42
-	/**
43
-	 * @param string $appName
44
-	 * @param IRequest $request
45
-	 * @param ICrypto $crypto
46
-	 * @param AccessTokenMapper $accessTokenMapper
47
-	 * @param DefaultTokenMapper $defaultTokenMapper
48
-	 * @param ISecureRandom $secureRandom
49
-	 */
50
-	public function __construct($appName,
51
-								IRequest $request,
52
-								ICrypto $crypto,
53
-								AccessTokenMapper $accessTokenMapper,
54
-								DefaultTokenMapper $defaultTokenMapper,
55
-								ISecureRandom $secureRandom) {
56
-		parent::__construct($appName, $request);
57
-		$this->crypto = $crypto;
58
-		$this->accessTokenMapper = $accessTokenMapper;
59
-		$this->defaultTokenMapper = $defaultTokenMapper;
60
-		$this->secureRandom = $secureRandom;
61
-	}
42
+    /**
43
+     * @param string $appName
44
+     * @param IRequest $request
45
+     * @param ICrypto $crypto
46
+     * @param AccessTokenMapper $accessTokenMapper
47
+     * @param DefaultTokenMapper $defaultTokenMapper
48
+     * @param ISecureRandom $secureRandom
49
+     */
50
+    public function __construct($appName,
51
+                                IRequest $request,
52
+                                ICrypto $crypto,
53
+                                AccessTokenMapper $accessTokenMapper,
54
+                                DefaultTokenMapper $defaultTokenMapper,
55
+                                ISecureRandom $secureRandom) {
56
+        parent::__construct($appName, $request);
57
+        $this->crypto = $crypto;
58
+        $this->accessTokenMapper = $accessTokenMapper;
59
+        $this->defaultTokenMapper = $defaultTokenMapper;
60
+        $this->secureRandom = $secureRandom;
61
+    }
62 62
 
63
-	/**
64
-	 * @PublicPage
65
-	 * @NoCSRFRequired
66
-	 *
67
-	 * @param string $code
68
-	 * @return JSONResponse
69
-	 */
70
-	public function getToken($code) {
71
-		$accessToken = $this->accessTokenMapper->getByCode($code);
72
-		$decryptedToken = $this->crypto->decrypt($accessToken->getEncryptedToken(), $code);
73
-		$newCode = $this->secureRandom->generate(128);
74
-		$accessToken->setHashedCode(hash('sha512', $newCode));
75
-		$accessToken->setEncryptedToken($this->crypto->encrypt($decryptedToken, $newCode));
76
-		$this->accessTokenMapper->update($accessToken);
63
+    /**
64
+     * @PublicPage
65
+     * @NoCSRFRequired
66
+     *
67
+     * @param string $code
68
+     * @return JSONResponse
69
+     */
70
+    public function getToken($code) {
71
+        $accessToken = $this->accessTokenMapper->getByCode($code);
72
+        $decryptedToken = $this->crypto->decrypt($accessToken->getEncryptedToken(), $code);
73
+        $newCode = $this->secureRandom->generate(128);
74
+        $accessToken->setHashedCode(hash('sha512', $newCode));
75
+        $accessToken->setEncryptedToken($this->crypto->encrypt($decryptedToken, $newCode));
76
+        $this->accessTokenMapper->update($accessToken);
77 77
 
78
-		return new JSONResponse(
79
-			[
80
-				'access_token' => $decryptedToken,
81
-				'token_type' => 'Bearer',
82
-				'expires_in' => 3600,
83
-				'refresh_token' => $newCode,
84
-				'user_id' => ($this->defaultTokenMapper->getTokenById($accessToken->getTokenId()))->getUID(),
85
-			]
86
-		);
87
-	}
78
+        return new JSONResponse(
79
+            [
80
+                'access_token' => $decryptedToken,
81
+                'token_type' => 'Bearer',
82
+                'expires_in' => 3600,
83
+                'refresh_token' => $newCode,
84
+                'user_id' => ($this->defaultTokenMapper->getTokenById($accessToken->getTokenId()))->getUID(),
85
+            ]
86
+        );
87
+    }
88 88
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Settings/Admin.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -27,41 +27,41 @@
 block discarded – undo
27 27
 use OCP\Settings\ISettings;
28 28
 
29 29
 class Admin implements ISettings {
30
-	/** @var ClientMapper */
31
-	private $clientMapper;
30
+    /** @var ClientMapper */
31
+    private $clientMapper;
32 32
 
33
-	/**
34
-	 * @param ClientMapper $clientMapper
35
-	 */
36
-	public function __construct(ClientMapper $clientMapper) {
37
-		$this->clientMapper = $clientMapper;
38
-	}
33
+    /**
34
+     * @param ClientMapper $clientMapper
35
+     */
36
+    public function __construct(ClientMapper $clientMapper) {
37
+        $this->clientMapper = $clientMapper;
38
+    }
39 39
 
40
-	/**
41
-	 * @return TemplateResponse
42
-	 */
43
-	public function getForm() {
44
-		return new TemplateResponse(
45
-			'oauth2',
46
-			'admin',
47
-			[
48
-				'clients' => $this->clientMapper->getClients(),
49
-			],
50
-			''
51
-		);
52
-	}
40
+    /**
41
+     * @return TemplateResponse
42
+     */
43
+    public function getForm() {
44
+        return new TemplateResponse(
45
+            'oauth2',
46
+            'admin',
47
+            [
48
+                'clients' => $this->clientMapper->getClients(),
49
+            ],
50
+            ''
51
+        );
52
+    }
53 53
 
54
-	/**
55
-	 * {@inheritdoc}
56
-	 */
57
-	public function getSection() {
58
-		return 'security';
59
-	}
54
+    /**
55
+     * {@inheritdoc}
56
+     */
57
+    public function getSection() {
58
+        return 'security';
59
+    }
60 60
 
61
-	/**
62
-	 * {@inheritdoc}
63
-	 */
64
-	public function getPriority() {
65
-		return 0;
66
-	}
61
+    /**
62
+     * {@inheritdoc}
63
+     */
64
+    public function getPriority() {
65
+        return 0;
66
+    }
67 67
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Auth.php 2 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -48,225 +48,225 @@
 block discarded – undo
48 48
 class Auth extends AbstractBasic {
49 49
 
50 50
 
51
-	const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
51
+    const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
52 52
 
53
-	/** @var ISession */
54
-	private $session;
55
-	/** @var Session */
56
-	private $userSession;
57
-	/** @var IRequest */
58
-	private $request;
59
-	/** @var string */
60
-	private $currentUser;
61
-	/** @var Manager */
62
-	private $twoFactorManager;
63
-	/** @var Throttler */
64
-	private $throttler;
53
+    /** @var ISession */
54
+    private $session;
55
+    /** @var Session */
56
+    private $userSession;
57
+    /** @var IRequest */
58
+    private $request;
59
+    /** @var string */
60
+    private $currentUser;
61
+    /** @var Manager */
62
+    private $twoFactorManager;
63
+    /** @var Throttler */
64
+    private $throttler;
65 65
 
66
-	/**
67
-	 * @param ISession $session
68
-	 * @param Session $userSession
69
-	 * @param IRequest $request
70
-	 * @param Manager $twoFactorManager
71
-	 * @param Throttler $throttler
72
-	 * @param string $principalPrefix
73
-	 */
74
-	public function __construct(ISession $session,
75
-								Session $userSession,
76
-								IRequest $request,
77
-								Manager $twoFactorManager,
78
-								Throttler $throttler,
79
-								$principalPrefix = 'principals/users/') {
80
-		$this->session = $session;
81
-		$this->userSession = $userSession;
82
-		$this->twoFactorManager = $twoFactorManager;
83
-		$this->request = $request;
84
-		$this->throttler = $throttler;
85
-		$this->principalPrefix = $principalPrefix;
66
+    /**
67
+     * @param ISession $session
68
+     * @param Session $userSession
69
+     * @param IRequest $request
70
+     * @param Manager $twoFactorManager
71
+     * @param Throttler $throttler
72
+     * @param string $principalPrefix
73
+     */
74
+    public function __construct(ISession $session,
75
+                                Session $userSession,
76
+                                IRequest $request,
77
+                                Manager $twoFactorManager,
78
+                                Throttler $throttler,
79
+                                $principalPrefix = 'principals/users/') {
80
+        $this->session = $session;
81
+        $this->userSession = $userSession;
82
+        $this->twoFactorManager = $twoFactorManager;
83
+        $this->request = $request;
84
+        $this->throttler = $throttler;
85
+        $this->principalPrefix = $principalPrefix;
86 86
 
87
-		// setup realm
88
-		$defaults = new \OCP\Defaults();
89
-		$this->realm = $defaults->getName();
90
-	}
87
+        // setup realm
88
+        $defaults = new \OCP\Defaults();
89
+        $this->realm = $defaults->getName();
90
+    }
91 91
 
92
-	/**
93
-	 * Whether the user has initially authenticated via DAV
94
-	 *
95
-	 * This is required for WebDAV clients that resent the cookies even when the
96
-	 * account was changed.
97
-	 *
98
-	 * @see https://github.com/owncloud/core/issues/13245
99
-	 *
100
-	 * @param string $username
101
-	 * @return bool
102
-	 */
103
-	public function isDavAuthenticated($username) {
104
-		return !is_null($this->session->get(self::DAV_AUTHENTICATED)) &&
105
-		$this->session->get(self::DAV_AUTHENTICATED) === $username;
106
-	}
92
+    /**
93
+     * Whether the user has initially authenticated via DAV
94
+     *
95
+     * This is required for WebDAV clients that resent the cookies even when the
96
+     * account was changed.
97
+     *
98
+     * @see https://github.com/owncloud/core/issues/13245
99
+     *
100
+     * @param string $username
101
+     * @return bool
102
+     */
103
+    public function isDavAuthenticated($username) {
104
+        return !is_null($this->session->get(self::DAV_AUTHENTICATED)) &&
105
+        $this->session->get(self::DAV_AUTHENTICATED) === $username;
106
+    }
107 107
 
108
-	/**
109
-	 * Validates a username and password
110
-	 *
111
-	 * This method should return true or false depending on if login
112
-	 * succeeded.
113
-	 *
114
-	 * @param string $username
115
-	 * @param string $password
116
-	 * @return bool
117
-	 * @throws PasswordLoginForbidden
118
-	 */
119
-	protected function validateUserPass($username, $password) {
120
-		if ($this->userSession->isLoggedIn() &&
121
-			$this->isDavAuthenticated($this->userSession->getUser()->getUID())
122
-		) {
123
-			\OC_Util::setupFS($this->userSession->getUser()->getUID());
124
-			$this->session->close();
125
-			return true;
126
-		} else {
127
-			\OC_Util::setupFS(); //login hooks may need early access to the filesystem
128
-			try {
129
-				if ($this->userSession->logClientIn($username, $password, $this->request, $this->throttler)) {
130
-					\OC_Util::setupFS($this->userSession->getUser()->getUID());
131
-					$this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
132
-					$this->session->close();
133
-					return true;
134
-				} else {
135
-					$this->session->close();
136
-					return false;
137
-				}
138
-			} catch (PasswordLoginForbiddenException $ex) {
139
-				$this->session->close();
140
-				throw new PasswordLoginForbidden();
141
-			}
142
-		}
143
-	}
108
+    /**
109
+     * Validates a username and password
110
+     *
111
+     * This method should return true or false depending on if login
112
+     * succeeded.
113
+     *
114
+     * @param string $username
115
+     * @param string $password
116
+     * @return bool
117
+     * @throws PasswordLoginForbidden
118
+     */
119
+    protected function validateUserPass($username, $password) {
120
+        if ($this->userSession->isLoggedIn() &&
121
+            $this->isDavAuthenticated($this->userSession->getUser()->getUID())
122
+        ) {
123
+            \OC_Util::setupFS($this->userSession->getUser()->getUID());
124
+            $this->session->close();
125
+            return true;
126
+        } else {
127
+            \OC_Util::setupFS(); //login hooks may need early access to the filesystem
128
+            try {
129
+                if ($this->userSession->logClientIn($username, $password, $this->request, $this->throttler)) {
130
+                    \OC_Util::setupFS($this->userSession->getUser()->getUID());
131
+                    $this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
132
+                    $this->session->close();
133
+                    return true;
134
+                } else {
135
+                    $this->session->close();
136
+                    return false;
137
+                }
138
+            } catch (PasswordLoginForbiddenException $ex) {
139
+                $this->session->close();
140
+                throw new PasswordLoginForbidden();
141
+            }
142
+        }
143
+    }
144 144
 
145
-	/**
146
-	 * @param RequestInterface $request
147
-	 * @param ResponseInterface $response
148
-	 * @return array
149
-	 * @throws NotAuthenticated
150
-	 * @throws ServiceUnavailable
151
-	 */
152
-	function check(RequestInterface $request, ResponseInterface $response) {
153
-		try {
154
-			$result = $this->auth($request, $response);
155
-			return $result;
156
-		} catch (NotAuthenticated $e) {
157
-			throw $e;
158
-		} catch (Exception $e) {
159
-			$class = get_class($e);
160
-			$msg = $e->getMessage();
161
-			\OC::$server->getLogger()->logException($e);
162
-			throw new ServiceUnavailable("$class: $msg");
163
-		}
164
-	}
145
+    /**
146
+     * @param RequestInterface $request
147
+     * @param ResponseInterface $response
148
+     * @return array
149
+     * @throws NotAuthenticated
150
+     * @throws ServiceUnavailable
151
+     */
152
+    function check(RequestInterface $request, ResponseInterface $response) {
153
+        try {
154
+            $result = $this->auth($request, $response);
155
+            return $result;
156
+        } catch (NotAuthenticated $e) {
157
+            throw $e;
158
+        } catch (Exception $e) {
159
+            $class = get_class($e);
160
+            $msg = $e->getMessage();
161
+            \OC::$server->getLogger()->logException($e);
162
+            throw new ServiceUnavailable("$class: $msg");
163
+        }
164
+    }
165 165
 
166
-	/**
167
-	 * Checks whether a CSRF check is required on the request
168
-	 *
169
-	 * @return bool
170
-	 */
171
-	private function requiresCSRFCheck() {
172
-		// GET requires no check at all
173
-		if($this->request->getMethod() === 'GET') {
174
-			return false;
175
-		}
166
+    /**
167
+     * Checks whether a CSRF check is required on the request
168
+     *
169
+     * @return bool
170
+     */
171
+    private function requiresCSRFCheck() {
172
+        // GET requires no check at all
173
+        if($this->request->getMethod() === 'GET') {
174
+            return false;
175
+        }
176 176
 
177
-		// Official Nextcloud clients require no checks
178
-		if($this->request->isUserAgent([
179
-			IRequest::USER_AGENT_CLIENT_DESKTOP,
180
-			IRequest::USER_AGENT_CLIENT_ANDROID,
181
-			IRequest::USER_AGENT_CLIENT_IOS,
182
-		])) {
183
-			return false;
184
-		}
177
+        // Official Nextcloud clients require no checks
178
+        if($this->request->isUserAgent([
179
+            IRequest::USER_AGENT_CLIENT_DESKTOP,
180
+            IRequest::USER_AGENT_CLIENT_ANDROID,
181
+            IRequest::USER_AGENT_CLIENT_IOS,
182
+        ])) {
183
+            return false;
184
+        }
185 185
 
186
-		// If not logged-in no check is required
187
-		if(!$this->userSession->isLoggedIn()) {
188
-			return false;
189
-		}
186
+        // If not logged-in no check is required
187
+        if(!$this->userSession->isLoggedIn()) {
188
+            return false;
189
+        }
190 190
 
191
-		// POST always requires a check
192
-		if($this->request->getMethod() === 'POST') {
193
-			return true;
194
-		}
191
+        // POST always requires a check
192
+        if($this->request->getMethod() === 'POST') {
193
+            return true;
194
+        }
195 195
 
196
-		// If logged-in AND DAV authenticated no check is required
197
-		if($this->userSession->isLoggedIn() &&
198
-			$this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199
-			return false;
200
-		}
196
+        // If logged-in AND DAV authenticated no check is required
197
+        if($this->userSession->isLoggedIn() &&
198
+            $this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199
+            return false;
200
+        }
201 201
 
202
-		return true;
203
-	}
202
+        return true;
203
+    }
204 204
 
205
-	/**
206
-	 * @param RequestInterface $request
207
-	 * @param ResponseInterface $response
208
-	 * @return array
209
-	 * @throws NotAuthenticated
210
-	 */
211
-	private function auth(RequestInterface $request, ResponseInterface $response) {
212
-		$forcedLogout = false;
205
+    /**
206
+     * @param RequestInterface $request
207
+     * @param ResponseInterface $response
208
+     * @return array
209
+     * @throws NotAuthenticated
210
+     */
211
+    private function auth(RequestInterface $request, ResponseInterface $response) {
212
+        $forcedLogout = false;
213 213
 
214
-		$authHeader = $request->getHeader('Authorization');
215
-		if (strpos($authHeader, 'Bearer ') !== false) {
216
-			if($this->userSession->tryTokenLogin($this->request)) {
217
-				$this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
218
-				$user = $this->userSession->getUser()->getUID();
219
-				\OC_Util::setupFS($user);
220
-				$this->currentUser = $user;
221
-				$this->session->close();
222
-				return [true, $this->principalPrefix . $user];
223
-			}
224
-		}
214
+        $authHeader = $request->getHeader('Authorization');
215
+        if (strpos($authHeader, 'Bearer ') !== false) {
216
+            if($this->userSession->tryTokenLogin($this->request)) {
217
+                $this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
218
+                $user = $this->userSession->getUser()->getUID();
219
+                \OC_Util::setupFS($user);
220
+                $this->currentUser = $user;
221
+                $this->session->close();
222
+                return [true, $this->principalPrefix . $user];
223
+            }
224
+        }
225 225
 
226
-		if(!$this->request->passesCSRFCheck() &&
227
-			$this->requiresCSRFCheck()) {
228
-			// In case of a fail with POST we need to recheck the credentials
229
-			if($this->request->getMethod() === 'POST') {
230
-				$forcedLogout = true;
231
-			} else {
232
-				$response->setStatus(401);
233
-				throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.');
234
-			}
235
-		}
226
+        if(!$this->request->passesCSRFCheck() &&
227
+            $this->requiresCSRFCheck()) {
228
+            // In case of a fail with POST we need to recheck the credentials
229
+            if($this->request->getMethod() === 'POST') {
230
+                $forcedLogout = true;
231
+            } else {
232
+                $response->setStatus(401);
233
+                throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.');
234
+            }
235
+        }
236 236
 
237
-		if($forcedLogout) {
238
-			$this->userSession->logout();
239
-		} else {
240
-			if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
241
-				throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
242
-			}
243
-			if (\OC_User::handleApacheAuth() ||
244
-				//Fix for broken webdav clients
245
-				($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) ||
246
-				//Well behaved clients that only send the cookie are allowed
247
-				($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null)
248
-			) {
249
-				$user = $this->userSession->getUser()->getUID();
250
-				\OC_Util::setupFS($user);
251
-				$this->currentUser = $user;
252
-				$this->session->close();
253
-				return [true, $this->principalPrefix . $user];
254
-			}
255
-		}
237
+        if($forcedLogout) {
238
+            $this->userSession->logout();
239
+        } else {
240
+            if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
241
+                throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
242
+            }
243
+            if (\OC_User::handleApacheAuth() ||
244
+                //Fix for broken webdav clients
245
+                ($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) ||
246
+                //Well behaved clients that only send the cookie are allowed
247
+                ($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null)
248
+            ) {
249
+                $user = $this->userSession->getUser()->getUID();
250
+                \OC_Util::setupFS($user);
251
+                $this->currentUser = $user;
252
+                $this->session->close();
253
+                return [true, $this->principalPrefix . $user];
254
+            }
255
+        }
256 256
 
257
-		if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
258
-			// do not re-authenticate over ajax, use dummy auth name to prevent browser popup
259
-			$response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
260
-			$response->setStatus(401);
261
-			throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
262
-		}
257
+        if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
258
+            // do not re-authenticate over ajax, use dummy auth name to prevent browser popup
259
+            $response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
260
+            $response->setStatus(401);
261
+            throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
262
+        }
263 263
 
264
-		$data = parent::check($request, $response);
265
-		if($data[0] === true) {
266
-			$startPos = strrpos($data[1], '/') + 1;
267
-			$user = $this->userSession->getUser()->getUID();
268
-			$data[1] = substr_replace($data[1], $user, $startPos);
269
-		}
270
-		return $data;
271
-	}
264
+        $data = parent::check($request, $response);
265
+        if($data[0] === true) {
266
+            $startPos = strrpos($data[1], '/') + 1;
267
+            $user = $this->userSession->getUser()->getUID();
268
+            $data[1] = substr_replace($data[1], $user, $startPos);
269
+        }
270
+        return $data;
271
+    }
272 272
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	private function requiresCSRFCheck() {
172 172
 		// GET requires no check at all
173
-		if($this->request->getMethod() === 'GET') {
173
+		if ($this->request->getMethod() === 'GET') {
174 174
 			return false;
175 175
 		}
176 176
 
177 177
 		// Official Nextcloud clients require no checks
178
-		if($this->request->isUserAgent([
178
+		if ($this->request->isUserAgent([
179 179
 			IRequest::USER_AGENT_CLIENT_DESKTOP,
180 180
 			IRequest::USER_AGENT_CLIENT_ANDROID,
181 181
 			IRequest::USER_AGENT_CLIENT_IOS,
@@ -184,17 +184,17 @@  discard block
 block discarded – undo
184 184
 		}
185 185
 
186 186
 		// If not logged-in no check is required
187
-		if(!$this->userSession->isLoggedIn()) {
187
+		if (!$this->userSession->isLoggedIn()) {
188 188
 			return false;
189 189
 		}
190 190
 
191 191
 		// POST always requires a check
192
-		if($this->request->getMethod() === 'POST') {
192
+		if ($this->request->getMethod() === 'POST') {
193 193
 			return true;
194 194
 		}
195 195
 
196 196
 		// If logged-in AND DAV authenticated no check is required
197
-		if($this->userSession->isLoggedIn() &&
197
+		if ($this->userSession->isLoggedIn() &&
198 198
 			$this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199 199
 			return false;
200 200
 		}
@@ -213,20 +213,20 @@  discard block
 block discarded – undo
213 213
 
214 214
 		$authHeader = $request->getHeader('Authorization');
215 215
 		if (strpos($authHeader, 'Bearer ') !== false) {
216
-			if($this->userSession->tryTokenLogin($this->request)) {
216
+			if ($this->userSession->tryTokenLogin($this->request)) {
217 217
 				$this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
218 218
 				$user = $this->userSession->getUser()->getUID();
219 219
 				\OC_Util::setupFS($user);
220 220
 				$this->currentUser = $user;
221 221
 				$this->session->close();
222
-				return [true, $this->principalPrefix . $user];
222
+				return [true, $this->principalPrefix.$user];
223 223
 			}
224 224
 		}
225 225
 
226
-		if(!$this->request->passesCSRFCheck() &&
226
+		if (!$this->request->passesCSRFCheck() &&
227 227
 			$this->requiresCSRFCheck()) {
228 228
 			// In case of a fail with POST we need to recheck the credentials
229
-			if($this->request->getMethod() === 'POST') {
229
+			if ($this->request->getMethod() === 'POST') {
230 230
 				$forcedLogout = true;
231 231
 			} else {
232 232
 				$response->setStatus(401);
@@ -234,10 +234,10 @@  discard block
 block discarded – undo
234 234
 			}
235 235
 		}
236 236
 
237
-		if($forcedLogout) {
237
+		if ($forcedLogout) {
238 238
 			$this->userSession->logout();
239 239
 		} else {
240
-			if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
240
+			if ($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
241 241
 				throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
242 242
 			}
243 243
 			if (\OC_User::handleApacheAuth() ||
@@ -250,19 +250,19 @@  discard block
 block discarded – undo
250 250
 				\OC_Util::setupFS($user);
251 251
 				$this->currentUser = $user;
252 252
 				$this->session->close();
253
-				return [true, $this->principalPrefix . $user];
253
+				return [true, $this->principalPrefix.$user];
254 254
 			}
255 255
 		}
256 256
 
257 257
 		if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
258 258
 			// do not re-authenticate over ajax, use dummy auth name to prevent browser popup
259
-			$response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
259
+			$response->addHeader('WWW-Authenticate', 'DummyBasic realm="'.$this->realm.'"');
260 260
 			$response->setStatus(401);
261 261
 			throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
262 262
 		}
263 263
 
264 264
 		$data = parent::check($request, $response);
265
-		if($data[0] === true) {
265
+		if ($data[0] === true) {
266 266
 			$startPos = strrpos($data[1], '/') + 1;
267 267
 			$user = $this->userSession->getUser()->getUID();
268 268
 			$data[1] = substr_replace($data[1], $user, $startPos);
Please login to merge, or discard this patch.
apps/oauth2/templates/admin.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
 				<td><?php p($client->getName()); ?></td>
51 51
 				<td><?php p($client->getRedirectUri()); ?></td>
52 52
 				<td><code><?php p($client->getClientIdentifier()); ?></code></td>
53
-				<td data-value="<?php p($client->getSecret()); ?>"><code>****</code><img class='show-oauth-credentials' src="<?php p($urlGenerator->imagePath('core', 'actions/toggle.svg'));?>"/></td>
53
+				<td data-value="<?php p($client->getSecret()); ?>"><code>****</code><img class='show-oauth-credentials' src="<?php p($urlGenerator->imagePath('core', 'actions/toggle.svg')); ?>"/></td>
54 54
 				<td>
55 55
 					<form id="form-inline" class="delete" action="<?php p($urlGenerator->linkToRoute('oauth2.Settings.deleteClient', ['id' => $client->getId()])); ?>" method="POST">
56 56
 						<input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']) ?>" />
Please login to merge, or discard this patch.