-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Personal settings auth tokens #24703
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
/** | ||
* @author Christoph Wurst <christoph@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2016, ownCloud, Inc. | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\Settings\Controller; | ||
|
||
use OC\AppFramework\Http; | ||
use OC\Authentication\Exceptions\InvalidTokenException; | ||
use OC\Authentication\Token\IProvider; | ||
use OC\Authentication\Token\IToken; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Http\JSONResponse; | ||
use OCP\IRequest; | ||
use OCP\ISession; | ||
use OCP\IUserManager; | ||
use OCP\Security\ISecureRandom; | ||
use OCP\Session\Exceptions\SessionNotAvailableException; | ||
|
||
class AuthSettingsController extends Controller { | ||
|
||
/** @var IProvider */ | ||
private $tokenProvider; | ||
|
||
/** @var IUserManager */ | ||
private $userManager; | ||
|
||
/** @var ISession */ | ||
private $session; | ||
|
||
/** @var string */ | ||
private $uid; | ||
|
||
/** @var ISecureRandom */ | ||
private $random; | ||
|
||
/** | ||
* @param string $appName | ||
* @param IRequest $request | ||
* @param IProvider $tokenProvider | ||
* @param IUserManager $userManager | ||
* @param ISession $session | ||
* @param ISecureRandom $random | ||
* @param string $uid | ||
*/ | ||
public function __construct($appName, IRequest $request, IProvider $tokenProvider, IUserManager $userManager, | ||
ISession $session, ISecureRandom $random, $uid) { | ||
parent::__construct($appName, $request); | ||
$this->tokenProvider = $tokenProvider; | ||
$this->userManager = $userManager; | ||
$this->uid = $uid; | ||
$this->session = $session; | ||
$this->random = $random; | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @NoSubadminRequired | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function index() { | ||
$user = $this->userManager->get($this->uid); | ||
if (is_null($user)) { | ||
return []; | ||
} | ||
return $this->tokenProvider->getTokenByUser($user); | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @NoSubadminRequired | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function create($name) { | ||
try { | ||
$sessionId = $this->session->getId(); | ||
} catch (SessionNotAvailableException $ex) { | ||
$resp = new JSONResponse(); | ||
$resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE); | ||
return $resp; | ||
} | ||
|
||
try { | ||
$sessionToken = $this->tokenProvider->getToken($sessionId); | ||
$password = $this->tokenProvider->getPassword($sessionToken, $sessionId); | ||
} catch (InvalidTokenException $ex) { | ||
$resp = new JSONResponse(); | ||
$resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE); | ||
return $resp; | ||
} | ||
|
||
$token = $this->generateRandomDeviceToken(); | ||
$deviceToken = $this->tokenProvider->generateToken($token, $this->uid, $password, $name, IToken::PERMANENT_TOKEN); | ||
|
||
return [ | ||
'token' => $token, | ||
'deviceToken' => $deviceToken | ||
]; | ||
} | ||
|
||
/** | ||
* Return a 20 digit device password | ||
* | ||
* Example: ABCDE-FGHIJ-KLMNO-PQRST | ||
* | ||
* @return string | ||
*/ | ||
private function generateRandomDeviceToken() { | ||
$groups = []; | ||
for ($i = 0; $i < 4; $i++) { | ||
$groups[] = $this->random->generate(5, implode('', range('A', 'Z'))); | ||
} | ||
return implode('-', $groups); | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* @NoSubadminRequired | ||
* | ||
* @return JSONResponse | ||
*/ | ||
public function destroy($id) { | ||
$user = $this->userManager->get($this->uid); | ||
if (is_null($user)) { | ||
return []; | ||
} | ||
|
||
$this->tokenProvider->invalidateTokenById($user, $id); | ||
return []; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,39 @@ input#identity { | |
table.nostyle label { margin-right: 2em; } | ||
table.nostyle td { padding: 0.2em 0; } | ||
|
||
#sessions table, | ||
#devices table { | ||
width: 100%; | ||
min-height: 150px; | ||
padding-top: 25px; | ||
} | ||
#sessions table th, | ||
#devices table th { | ||
font-weight: 800; | ||
} | ||
#sessions table th, | ||
#sessions table td, | ||
#devices table th, | ||
#devices table td { | ||
padding: 10px; | ||
} | ||
|
||
#sessions .token-list td, | ||
#devices .token-list td { | ||
border-top: 1px solid #DDD; | ||
} | ||
#sessions .token-list td a.icon-delete, | ||
#devices .token-list td a.icon-delete { | ||
display: block; | ||
opacity: 0.6; | ||
} | ||
|
||
#device-new-token { | ||
width: 186px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if someone knows a better way let me know |
||
font-family: monospace; | ||
background-color: lightyellow; | ||
} | ||
|
||
/* USERS */ | ||
#newgroup-init a span { margin-left: 20px; } | ||
#newgroup-init a span:before { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not required, because id is unique?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or don't you check ownership before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, I want to prevent users deleting other users tokens
https://github.com/owncloud/core/pull/24703/files#diff-86dbc8c463c390f9fcc767a856c332a3R147