Fixes #6444, #6419 oauth2 redirect, imports (#6445)
[openemr.git] / src / Common / Auth / OpenIDConnect / Entities / ClientEntity.php
blob72a0ab7710ec4deb51e12e294c61b07bb61db962
1 <?php
3 /**
4 * Authorization Server Member
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Jerry Padgett <sjpadgett@gmail.com>
9 * @copyright Copyright (c) 2020 Jerry Padgett <sjpadgett@gmail.com>
10 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
13 namespace OpenEMR\Common\Auth\OpenIDConnect\Entities;
15 use League\OAuth2\Server\Entities\ClientEntityInterface;
16 use League\OAuth2\Server\Entities\Traits\ClientTrait;
17 use League\OAuth2\Server\Entities\Traits\EntityTrait;
19 class ClientEntity implements ClientEntityInterface
21 use EntityTrait;
22 use ClientTrait;
24 protected $userId;
25 protected $clientRole;
26 protected $scopes;
27 protected $launchUri;
29 protected $jwks;
31 protected $jwksUri;
33 /**
34 * Confidential apps or apps with a 'launch' scope must be manually authorized by an adminstrator before their
35 * client can be used.
36 * @var bool
38 protected $isEnabled;
40 /**
41 * @var array[] Array of trusted user objects
43 protected $trustedUsers;
45 /**
46 * @var string[] The list of contact email addresses to reach out for questions about the client app
48 protected $contacts;
50 /**
51 * @var string The logout uri to send users to to logout from the application.
53 protected $logoutRedirectUris;
55 protected $registrationDate;
57 public function __construct()
59 $this->scopes = [];
62 public function setName($name): void
64 $this->name = $name;
67 public function setRedirectUri($uri): void
69 if (\is_string($uri)) {
70 $this->redirectUri = [$uri];
71 } else if (\is_array($uri)) {
72 $this->redirectUri = $uri;
73 } else {
74 throw new \InvalidArgumentException("redirectUri must be a string or array");
78 public function setIsConfidential($set): void
80 $this->isConfidential = $set;
83 public function setIsEnabled($set): void
85 $this->isEnabled = $set === 1 || $set === true;
88 public function isEnabled(): bool
90 return $this->isEnabled;
93 public function setUserId($id): void
95 $this->userId = $id;
98 public function getUserId()
100 return $this->userId;
103 public function setClientRole($role): void
105 $this->clientRole = $role;
108 public function getClientRole()
110 return $this->clientRole;
113 public function getScopes()
115 return $this->scopes;
117 public function setScopes($scopes)
119 // clear out the scopes if our scopes are empty
120 if (empty($scopes)) {
121 $this->scopes = [];
122 return;
125 if (is_string($scopes)) {
126 $scopes = explode(" ", $scopes);
127 } else if (!is_array($scopes)) {
128 throw new \InvalidArgumentException("scopes parameter must be a valid array or string");
130 $this->scopes = $scopes;
134 * Checks if a given entity
135 * @param $scope
136 * @return bool
138 public function hasScope($scope)
140 return in_array($scope, $this->scopes);
144 * Returns the registered launch URI (as a string).
146 * @params $launchParams string A URL query string params to append to the launch uri.
147 * @return string
149 public function getLaunchUri($launchParams = '')
151 $launchParams = isset($launchParams) ? $launchParams : '';
152 return $this->launchUri . $launchParams;
155 public function setLaunchUri($uri): void
157 $this->launchUri = $uri;
161 * @return string
163 public function getJwks()
165 return $this->jwks;
169 * @return string
171 public function getJwksUri()
173 return $this->jwksUri;
177 * @param string $jwks
179 public function setJwks($jwks): void
181 $this->jwks = $jwks;
185 * @param string $jwksUri
187 public function setJwksUri($jwksUri): void
189 $this->jwksUri = $jwksUri;
193 * Array of records from the oauth2_trusted_users table
194 * @return array[]
196 public function getTrustedUsers(): array
198 return $this->trustedUsers;
202 * Set the trusted user records (these come from the oauth2_trusted_users table
203 * @param array $trustedUsers
205 public function setTrustedUsers(array $trustedUsers)
207 $this->trustedUsers = $trustedUsers;
210 public function getContacts()
212 return $this->contacts;
215 public function setContacts($contacts)
217 $this->contacts = $contacts;
220 public function setRegistrationDate($registerDate)
222 $this->registrationDate = $registerDate;
225 public function getRegistrationDate()
227 return $this->registrationDate;
231 * @return string
233 public function getLogoutRedirectUris(): string
235 return $this->logoutRedirectUris;
239 * @param string $logoutRedirectUris
241 public function setLogoutRedirectUris(?string $logoutRedirectUris): void
243 $this->logoutRedirectUris = $logoutRedirectUris;