Skip to content

Commit

Permalink
Merge branch 'feature/more-user-vals' into 'main'
Browse files Browse the repository at this point in the history
feat: enhance default user

See merge request internal/oauth2-client-php!9
  • Loading branch information
marge-bot committed Feb 27, 2024
2 parents b0716c0 + c6c7e7f commit bb58393
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 41 additions & 8 deletions src/AuthServiceUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

namespace Bookboon\OauthClient;

use League\OAuth2\Client\Token\AccessTokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;

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[]
Expand Down Expand Up @@ -53,7 +57,7 @@ public function getUsername(): string
return $this->username;
}

public function getToken(): ?string
public function getAccessToken(): ?AccessTokenInterface
{
return $this->token;
}
Expand All @@ -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
{
}

Expand All @@ -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;
}
}
5 changes: 4 additions & 1 deletion src/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/BookboonResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
*/
Expand Down

0 comments on commit bb58393

Please sign in to comment.