You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
4.8 KiB

3 years ago
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Marcel Waldvogel <marcel.waldvogel@uni-konstanz.de>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OC\Authentication\Token;
  29. use OC\Authentication\Exceptions\ExpiredTokenException;
  30. use OC\Authentication\Exceptions\InvalidTokenException;
  31. use OC\Authentication\Exceptions\PasswordlessTokenException;
  32. use OC\Authentication\Exceptions\WipeTokenException;
  33. interface IProvider {
  34. /**
  35. * Create and persist a new token
  36. *
  37. * @param string $token
  38. * @param string $uid
  39. * @param string $loginName
  40. * @param string|null $password
  41. * @param string $name
  42. * @param int $type token type
  43. * @param int $remember whether the session token should be used for remember-me
  44. * @return IToken
  45. * @throws \RuntimeException when OpenSSL reports a problem
  46. */
  47. public function generateToken(string $token,
  48. string $uid,
  49. string $loginName,
  50. $password,
  51. string $name,
  52. int $type = IToken::TEMPORARY_TOKEN,
  53. int $remember = IToken::DO_NOT_REMEMBER): IToken;
  54. /**
  55. * Get a token by token id
  56. *
  57. * @param string $tokenId
  58. * @throws InvalidTokenException
  59. * @throws ExpiredTokenException
  60. * @throws WipeTokenException
  61. * @return IToken
  62. */
  63. public function getToken(string $tokenId): IToken;
  64. /**
  65. * Get a token by token id
  66. *
  67. * @param int $tokenId
  68. * @throws InvalidTokenException
  69. * @throws ExpiredTokenException
  70. * @throws WipeTokenException
  71. * @return IToken
  72. */
  73. public function getTokenById(int $tokenId): IToken;
  74. /**
  75. * Duplicate an existing session token
  76. *
  77. * @param string $oldSessionId
  78. * @param string $sessionId
  79. * @throws InvalidTokenException
  80. * @throws \RuntimeException when OpenSSL reports a problem
  81. * @return IToken The new token
  82. */
  83. public function renewSessionToken(string $oldSessionId, string $sessionId): IToken;
  84. /**
  85. * Invalidate (delete) the given session token
  86. *
  87. * @param string $token
  88. */
  89. public function invalidateToken(string $token);
  90. /**
  91. * Invalidate (delete) the given token
  92. *
  93. * @param string $uid
  94. * @param int $id
  95. */
  96. public function invalidateTokenById(string $uid, int $id);
  97. /**
  98. * Invalidate (delete) old session tokens
  99. */
  100. public function invalidateOldTokens();
  101. /**
  102. * Save the updated token
  103. *
  104. * @param IToken $token
  105. */
  106. public function updateToken(IToken $token);
  107. /**
  108. * Update token activity timestamp
  109. *
  110. * @param IToken $token
  111. */
  112. public function updateTokenActivity(IToken $token);
  113. /**
  114. * Get all tokens of a user
  115. *
  116. * The provider may limit the number of result rows in case of an abuse
  117. * where a high number of (session) tokens is generated
  118. *
  119. * @param string $uid
  120. * @return IToken[]
  121. */
  122. public function getTokenByUser(string $uid): array;
  123. /**
  124. * Get the (unencrypted) password of the given token
  125. *
  126. * @param IToken $savedToken
  127. * @param string $tokenId
  128. * @throws InvalidTokenException
  129. * @throws PasswordlessTokenException
  130. * @return string
  131. */
  132. public function getPassword(IToken $savedToken, string $tokenId): string;
  133. /**
  134. * Encrypt and set the password of the given token
  135. *
  136. * @param IToken $token
  137. * @param string $tokenId
  138. * @param string $password
  139. * @throws InvalidTokenException
  140. */
  141. public function setPassword(IToken $token, string $tokenId, string $password);
  142. /**
  143. * Rotate the token. Usefull for for example oauth tokens
  144. *
  145. * @param IToken $token
  146. * @param string $oldTokenId
  147. * @param string $newTokenId
  148. * @return IToken
  149. * @throws \RuntimeException when OpenSSL reports a problem
  150. */
  151. public function rotate(IToken $token, string $oldTokenId, string $newTokenId): IToken;
  152. /**
  153. * Marks a token as having an invalid password.
  154. *
  155. * @param IToken $token
  156. * @param string $tokenId
  157. */
  158. public function markPasswordInvalid(IToken $token, string $tokenId);
  159. /**
  160. * Update all the passwords of $uid if required
  161. *
  162. * @param string $uid
  163. * @param string $password
  164. */
  165. public function updatePasswords(string $uid, string $password);
  166. }