Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to set the access token on entity provider. #18

Open
wants to merge 1 commit into
base: feature/2.1
Choose a base branch
from
Open
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
22 changes: 17 additions & 5 deletions src/Provider/XiboEntityProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public function getLogger()
{
return $this->logger;
}

/**
* Set the access token
* for example, if the access token has been stored in a data store, we should not have to get a new one
* @param $accessToken
* @return $this
*/
public function setAccessToken($accessToken) {
$this->token = $accessToken;
return $this;
}

/**
* Get Access Token
Expand All @@ -75,17 +86,18 @@ public function getLogger()
*/
private function getAccessToken()
{
if ($this->provider === null)
if ($this->provider === null) {
throw new EmptyProviderException();
}

$this->getLogger()->debug('Checking Access token and requesting a new one if necessary');

if ($this->token == null || $this->token->hasExpired() || $this->token->getExpires() <= time() + 10) {
// Get and store a new token
$this->getLogger()->info('Getting a new Access Token');
$this->getLogger()->info('Getting a new Access Token');
$this->token = $this->provider->getAccessToken('client_credentials');
}
else {
$this->token = $this->token;
}

return $this->token;
}

Expand Down