ScopeRepository.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace oauth2\repository;
  3. use oauth2\entity\ScopeEntity;
  4. use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
  5. use League\OAuth2\Server\Entities\ClientEntityInterface;
  6. use League\OAuth2\Server\Entities\ScopeEntityInterface;
  7. /**
  8. * Class ScopeRepository
  9. * @package oauth2
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class ScopeRepository implements ScopeRepositoryInterface
  13. {
  14. /**
  15. * Return information about a scope.
  16. *
  17. * @param string $identifier The scope identifier
  18. *
  19. * @return ScopeEntityInterface
  20. */
  21. public function getScopeEntityByIdentifier($identifier)
  22. {
  23. // 验证权限是否在权限范围中会调用此方法
  24. // 参数为单个权限标识符
  25. // ......
  26. // 验证成功则返回 ScopeEntityInterface 对象
  27. $scope = new ScopeEntity();
  28. $scope->setIdentifier($identifier);
  29. return $scope;
  30. }
  31. /**
  32. * Given a client, grant type and optional user identifier validate the set of scopes requested are valid and optionally
  33. * append additional scopes or remove requested scopes.
  34. *
  35. * @param ScopeEntityInterface[] $scopes
  36. * @param string $grantType
  37. * @param ClientEntityInterface $clientEntity
  38. * @param null|string $userIdentifier
  39. *
  40. * @return ScopeEntityInterface[]
  41. */
  42. public function finalizeScopes(
  43. array $scopes,
  44. $grantType,
  45. ClientEntityInterface $clientEntity,
  46. $userIdentifier = null
  47. ) {
  48. // 在创建授权码与访问令牌前会调用此方法
  49. // 用于验证权限范围、授权类型、客户端、用户是否匹配
  50. // 可整合进项目自身的权限控制中
  51. // 必须返回 ScopeEntityInterface 对象可用的 scope 数组
  52. // 示例:
  53. // $scope = new ScopeEntity();
  54. // $scope->setIdentifier('example');
  55. // $scopes[] = $scope;
  56. return $scopes;
  57. }
  58. }
粤ICP备19079148号