IProvider.php 4.4 KB

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