Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to `laravel-xero-oauth2` will be documented in this file

## v4.0.0 Release
- Support multiple tenants on one connection #71

> **Note**
> Unless you are using a custom OauthCredentialStore then this should be an in-place update, however you may be required to
> wipe and re-enable your credential storage.


## v3.0.0 Release
- Change FileStore to use FilesystemManager with disk configuration #67
- Drop Laravel 5 support
Expand Down
17 changes: 13 additions & 4 deletions src/Oauth2CredentialManagers/CacheStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,18 @@ public function getRefreshToken(): string
return $this->data('refresh_token');
}

public function getTenantId(): string
public function getTenants(): ?array
{
return $this->data('tenant_id');
return $this->data('tenants');
}

public function getTenantId(int $tenant =0): string
{
if(!isset($this->data('tenants')[$tenant]))
{
throw new \Exception("No such tenant exists");
}
return $this->data('tenants')[$tenant]['Id'];
}

public function getExpires(): int
Expand Down Expand Up @@ -88,14 +97,14 @@ public function refresh(): void
$this->store($newAccessToken);
}

public function store(AccessTokenInterface $token, string $tenantId = null): void
public function store(AccessTokenInterface $token, array $tenants = null): void
{
$this->cache->forever($this->cacheKey, [
'token' => $token->getToken(),
'refresh_token' => $token->getRefreshToken(),
'id_token' => $token->getValues()['id_token'],
'expires' => $token->getExpires(),
'tenant_id' => $tenantId ?? $this->getTenantId()
'tenants' => $tenants ?? $this->getTenants()
]);
}

Expand Down
17 changes: 13 additions & 4 deletions src/Oauth2CredentialManagers/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ public function getRefreshToken(): string
return $this->data('refresh_token');
}

public function getTenantId(): string
public function getTenants(): ?array
{
return $this->data('tenant_id');
return $this->data('tenants');
}

public function getTenantId(int $tenant =0): string
{
if(!isset($this->data('tenants')[$tenant]))
{
throw new \Exception("No such tenant exists");
}
return $this->data('tenants')[$tenant]['Id'];
}

public function getExpires(): int
Expand Down Expand Up @@ -90,14 +99,14 @@ public function refresh(): void
$this->store($newAccessToken);
}

public function store(AccessTokenInterface $token, string $tenantId = null): void
public function store(AccessTokenInterface $token, array $tenants = null): void
{
$ret = $this->disk->put($this->filePath, json_encode([
'token' => $token->getToken(),
'refresh_token' => $token->getRefreshToken(),
'id_token' => $token->getValues()['id_token'],
'expires' => $token->getExpires(),
'tenant_id' => $tenantId ?? $this->getTenantId()
'tenants' => $tenants ?? $this->getTenants()
]), 'private');

if ($ret === false) {
Expand Down
17 changes: 11 additions & 6 deletions src/OauthCredentialManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ public function getRefreshToken(): string;
*/
public function getAuthorizationUrl(): string;

/**
* Get all tenants available
**/
public function getTenants(): ?array;

/**
* Get the current tenant ID
*/
public function getTenantId(): string;
public function getTenantId(int $tenant =0): string;

/**
* Get the time the current access token expires (unix timestamp)
Expand Down Expand Up @@ -59,13 +64,13 @@ public function refresh(): void;
* 'refresh_token' => $token->getRefreshToken(),
* 'id_token' => $token->getValues()['id_token'],
* 'expires' => $token->getExpires(),
* 'tenant_id' => $tenantId ?? $this->getTenantId(),
* 'tenants' => $tenants ?? $this->getTenants(),
* ]
*
* @param AccessTokenInterface $token
* @param string|null $tenantId
* @param Array|null $tenants
*/
public function store(AccessTokenInterface $token, string $tenantId = null): void;
public function store(AccessTokenInterface $token, array $tenants = null): void;

/**
* Get the current authenticated users details according to the id token
Expand All @@ -87,9 +92,9 @@ public function getUser(): ?array;
* 'refresh_token' => 'string',
* 'id_token' => 'string',
* 'expires' => 000000,
* 'tenant_id' => 'string',
* 'tenants' => 'array',
* ]
*/
public function getData(): array;

}
}