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
[stable12] Improve OAuth #9546
Merged
Merged
[stable12] Improve OAuth #9546
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0885bd4
Allow the rotation of tokens
rullzer f2a3115
Certain tokens can expire
rullzer 1525cc2
Set OAuth token expiration
rullzer aa78c30
Fail if the response type is not properly set
rullzer c2a21ea
Authenticate the clients on requesting a token
rullzer 335f4ef
Rotate token
rullzer 44735de
Don't use special chars to avoid confusion
rullzer c2f09e4
Add tests
rullzer 3e57666
Properly set expires to NULL when creating a token
rullzer File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright 2018, Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @author Roeland Jago Douma <roeland@famdouma.nl> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* 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 | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\OAuth2\Migration; | ||
|
||
use OC\Authentication\Exceptions\InvalidTokenException; | ||
use OC\Authentication\Token\IProvider as TokenProvider; | ||
use OCA\OAuth2\Db\AccessToken; | ||
use OCP\AppFramework\Utility\ITimeFactory; | ||
use OCP\IDBConnection; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\IRepairStep; | ||
|
||
class SetTokenExpiration implements IRepairStep { | ||
|
||
/** @var IDBConnection */ | ||
private $connection; | ||
|
||
/** @var ITimeFactory */ | ||
private $time; | ||
|
||
/** @var TokenProvider */ | ||
private $tokenProvider; | ||
|
||
public function __construct(IDBConnection $connection, | ||
ITimeFactory $timeFactory, | ||
TokenProvider $tokenProvider) { | ||
$this->connection = $connection; | ||
$this->time = $timeFactory; | ||
$this->tokenProvider = $tokenProvider; | ||
} | ||
|
||
public function getName() { | ||
return 'Update OAuth token expiration times'; | ||
} | ||
|
||
public function run(IOutput $output) { | ||
$qb = $this->connection->getQueryBuilder(); | ||
$qb->select('*') | ||
->from('oauth2_access_tokens'); | ||
|
||
$cursor = $qb->execute(); | ||
|
||
while($row = $cursor->fetch()) { | ||
$token = AccessToken::fromRow($row); | ||
try { | ||
$appToken = $this->tokenProvider->getTokenById($token->getTokenId()); | ||
$appToken->setExpires($this->time->getTime() + 3600); | ||
$this->tokenProvider->updateToken($appToken); | ||
} catch (InvalidTokenException $e) { | ||
//Skip this token | ||
} | ||
} | ||
$cursor->closeCursor(); | ||
} | ||
|
||
} |
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
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.
Didn't see this in the original PR, but wouldn't it make sense to at least have a debug log statement for this in case we have to trace bugs in this code?