IProvider.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * @author Christoph Wurst <christoph@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Authentication\Token;
  22. use OC\Authentication\Exceptions\InvalidTokenException;
  23. use OC\Authentication\Exceptions\PasswordlessTokenException;
  24. use OCP\IUser;
  25. interface IProvider {
  26. /**
  27. * Create and persist a new token
  28. *
  29. * @param string $token
  30. * @param string $uid
  31. * @param string $loginName
  32. * @param string|null $password
  33. * @param string $name
  34. * @param int $type token type
  35. * @return IToken
  36. */
  37. public function generateToken($token, $uid, $loginName, $password, $name, $type = IToken::TEMPORARY_TOKEN);
  38. /**
  39. * Get a token by token id
  40. *
  41. * @param string $tokenId
  42. * @throws InvalidTokenException
  43. * @return IToken
  44. */
  45. public function getToken($tokenId) ;
  46. /**
  47. * Invalidate (delete) the given session token
  48. *
  49. * @param string $token
  50. */
  51. public function invalidateToken($token);
  52. /**
  53. * Invalidate (delete) the given token
  54. *
  55. * @param IUser $user
  56. * @param int $id
  57. */
  58. public function invalidateTokenById(IUser $user, $id);
  59. /**
  60. * Save the updated token
  61. *
  62. * @param IToken $token
  63. */
  64. public function updateToken(IToken $token);
  65. /**
  66. * Update token activity timestamp
  67. *
  68. * @param IToken $token
  69. */
  70. public function updateTokenActivity(IToken $token);
  71. /**
  72. * Get all token of a user
  73. *
  74. * The provider may limit the number of result rows in case of an abuse
  75. * where a high number of (session) tokens is generated
  76. *
  77. * @param IUser $user
  78. * @return IToken[]
  79. */
  80. public function getTokenByUser(IUser $user);
  81. /**
  82. * Get the (unencrypted) password of the given token
  83. *
  84. * @param IToken $token
  85. * @param string $tokenId
  86. * @throws InvalidTokenException
  87. * @throws PasswordlessTokenException
  88. * @return string
  89. */
  90. public function getPassword(IToken $token, $tokenId);
  91. /**
  92. * Encrypt and set the password of the given token
  93. *
  94. * @param IToken $token
  95. * @param string $tokenId
  96. * @param string $password
  97. * @throws InvalidTokenException
  98. */
  99. public function setPassword(IToken $token, $tokenId, $password);
  100. }