From c6c7e7f0ea473e3d267444595ae960927ca4e67d Mon Sep 17 00:00:00 2001 From: Lasse Mammen Date: Tue, 27 Feb 2024 16:54:56 +0000 Subject: [PATCH] feat: enhance default user Tested-by: marge-bot Part-of: --- .gitlab-ci.yml | 2 +- src/AuthServiceUser.php | 49 +++++++++++++++++++++++++++++------ src/Authenticator.php | 5 +++- src/BookboonResourceOwner.php | 15 +++++++++++ 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b63f6a1..08908d7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ stages: - security variables: - PHP_IMAGE: registry.bookbooncloud.com/docker/php-base:8.1.8 + PHP_IMAGE: registry.bookbooncloud.com/docker/php-base:8.2.14 .auto_devops: &auto_devops | # Auto DevOps variables and functions diff --git a/src/AuthServiceUser.php b/src/AuthServiceUser.php index 903e33b..7348516 100644 --- a/src/AuthServiceUser.php +++ b/src/AuthServiceUser.php @@ -2,6 +2,7 @@ namespace Bookboon\OauthClient; +use League\OAuth2\Client\Token\AccessTokenInterface; use Symfony\Component\Security\Core\User\UserInterface; class AuthServiceUser implements UserInterface @@ -9,8 +10,11 @@ class AuthServiceUser implements UserInterface private string $userId = ''; private string $username = ''; private array $roles = []; - private ?string $token = null; private ?string $email = null; + private ?AccessTokenInterface $token = null; + private ?string $applicationId = null; + private ?string $organisationId = null; + private ?string $blobId = null; /** * @return string[] @@ -53,7 +57,7 @@ public function getUsername(): string return $this->username; } - public function getToken(): ?string + public function getAccessToken(): ?AccessTokenInterface { return $this->token; } @@ -78,10 +82,22 @@ public function getSalt(): string return ''; } - /** - * @return void - */ - public function eraseCredentials() + public function getOrganisationId(): ?string + { + return $this->organisationId; + } + + public function getApplicationId(): ?string + { + return $this->applicationId; + } + + public function getBlobId(): ?string + { + return $this->blobId; + } + + public function eraseCredentials(): void { } @@ -102,16 +118,33 @@ public function setRoles(array $roles): static $this->roles = $roles; return $this; } - - public function setToken(string $token): static + public function setAccessToken(AccessTokenInterface $token): static { $this->token = $token; return $this; } + public function setOrganisationId(?string $organisationId): static + { + $this->organisationId = $organisationId; + return $this; + } + + public function setApplicationId(?string $applicationId): static + { + $this->applicationId = $applicationId; + return $this; + } + public function setEmail(?string $email): static { $this->email = $email; return $this; } + + public function setBlobId(?string $blobId): static + { + $this->blobId = $blobId; + return $this; + } } diff --git a/src/Authenticator.php b/src/Authenticator.php index 0bf997c..cf296a3 100644 --- a/src/Authenticator.php +++ b/src/Authenticator.php @@ -58,9 +58,12 @@ public function authenticate(Request $request): Passport $user = (new AuthServiceUser()) ->setUserId($resourceOwner->getId()) ->setUsername($resourceOwner->getName()) + ->setApplicationId($resourceOwner->getApplicationId()) + ->setOrganisationId($resourceOwner->getOrganisationId()) + ->setBlobId($resourceOwner->getBlobId()) ->setRoles($resourceOwner->getRoles()) ->setEmail($resourceOwner->getEmail()) - ->setToken($accessToken->getToken()); + ->setAccessToken($accessToken); } return $user; diff --git a/src/BookboonResourceOwner.php b/src/BookboonResourceOwner.php index a886638..d813a0c 100644 --- a/src/BookboonResourceOwner.php +++ b/src/BookboonResourceOwner.php @@ -70,6 +70,21 @@ public function getRoles() return $this->getValueByKey($this->response, 'user.roles'); } + public function getBlobId() + { + return $this->getValueByKey($this->response, 'user.blobId'); + } + + public function getOrganisationId() + { + return $this->getValueByKey($this->response, 'application.organisation.id'); + } + + public function getApplicationId() + { + return $this->getValueByKey($this->response, 'application.id'); + } + /** * @return string[] */