Skip to content

Commit

Permalink
Fixing missing oc_authtoken for native clients #27845
Browse files Browse the repository at this point in the history
Current token must be not null

Generate auth token for http_basic_auth logins

Cleanup
  • Loading branch information
IljaN committed Oct 11, 2017
1 parent 2ac86a5 commit 6d2a2a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/private/legacy/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ public static function loadApps($types = null) {
$davUser = \OC::$server->getUserSession()->getSession()->get(\OCA\DAV\Connector\Sabre\Auth::DAV_AUTHENTICATED);
if (is_null($davUser)) {
\OC::$server->getUserSession()->validateSession();
} else {
$request = \OC::$server->getRequest();
$userSession = \OC::$server->getUserSession();
/** @var \OC\Authentication\Token\DefaultTokenProvider $tokenProvider */
$tokenProvider = \OC::$server->query('\OC\Authentication\Token\DefaultTokenProvider');
$token = null;
try {
$token = $tokenProvider->getToken($userSession->getSession()->getId());
} catch (\Exception $ex) {
$password = null;
if (isset($_SERVER['PHP_AUTH_PW'])) {
$password = $_SERVER['PHP_AUTH_PW'];
}

$userSession->createSessionToken($request, $userSession->getUser()->getUID(), $userSession->getLoginName(), $password);
}

if ($token) {
$tokenProvider->updateToken($token);
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions settings/Controller/AuthSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,15 @@ private function generateRandomDeviceToken() {
* @return JSONResponse
*/
public function destroy($id) {

$user = $this->userManager->get($this->uid);
$currentToken = $this->tokenProvider->getToken($this->session->getId());

if ($currentToken && ($currentToken->getId() === intval($id))) {
return (new JSONResponse())->setStatus(Http::STATUS_CONFLICT);
}


if (is_null($user)) {
return [];
}
Expand Down

0 comments on commit 6d2a2a8

Please sign in to comment.