diff options
author | Christoph Wurst <christoph@owncloud.com> | 2016-04-27 09:38:30 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-05-11 13:36:46 +0200 |
commit | fdc2cd755477220c027e026aa70594af87427bed (patch) | |
tree | 74fccc3156ed16b44e48189616a8019012f07703 /lib/private/Authentication/Token | |
parent | 8d4850218740b74faae5af637d1b1c2b3dee3c41 (diff) | |
download | nextcloud-server-fdc2cd755477220c027e026aa70594af87427bed.tar.gz nextcloud-server-fdc2cd755477220c027e026aa70594af87427bed.zip |
Add token auth for OCS APIs
Diffstat (limited to 'lib/private/Authentication/Token')
4 files changed, 26 insertions, 4 deletions
diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php index 78b5c2d6116..70562502b76 100644 --- a/lib/private/Authentication/Token/DefaultToken.php +++ b/lib/private/Authentication/Token/DefaultToken.php @@ -60,4 +60,8 @@ class DefaultToken extends Entity implements IToken { return $this->id; } + public function getUid() { + return $this->uid; + } + } diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index a4e44f3c5d2..97567e53cd0 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -83,7 +83,11 @@ class DefaultTokenProvider implements IProvider { * * @param DefaultToken $token */ - public function updateToken(DefaultToken $token) { + public function updateToken(IToken $token) { + if (!($token instanceof DefaultToken)) { + throw new InvalidTokenException(); + } + /** @var DefaultToken $token */ $token->setLastActivity(time()); $this->mapper->update($token); @@ -130,14 +134,14 @@ class DefaultTokenProvider implements IProvider { /** * @param string $token * @throws InvalidTokenException - * @return string user UID + * @return IToken user UID */ public function validateToken($token) { $this->logger->debug('validating default token <' . $token . '>'); try { $dbToken = $this->mapper->getToken($this->hashToken($token)); $this->logger->debug('valid token for ' . $dbToken->getUid()); - return $dbToken->getUid(); + return $dbToken; } catch (DoesNotExistException $ex) { $this->logger->warning('invalid token'); throw new InvalidTokenException(); diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php index 4fceef19a1c..5c0b0d140ae 100644 --- a/lib/private/Authentication/Token/IProvider.php +++ b/lib/private/Authentication/Token/IProvider.php @@ -29,7 +29,14 @@ interface IProvider { /** * @param string $token * @throws InvalidTokenException - * @return string user UID + * @return IToken */ public function validateToken($token); + + /** + * Update token activity timestamp + * + * @param DefaultToken $token + */ + public function updateToken(IToken $token); } diff --git a/lib/private/Authentication/Token/IToken.php b/lib/private/Authentication/Token/IToken.php index 549a1f98268..90feefb4589 100644 --- a/lib/private/Authentication/Token/IToken.php +++ b/lib/private/Authentication/Token/IToken.php @@ -36,4 +36,11 @@ interface IToken { * @return string */ public function getId(); + + /** + * Get the user UID + * + * @return string + */ + public function getUid(); } |