Skip to content

Commit

Permalink
Improve service request processing
Browse files Browse the repository at this point in the history
Add fallback to earlier outcomes services when one fails
Better handling of access tokens
  • Loading branch information
spvickers committed Aug 17, 2020
1 parent 6b5a81f commit e17cbb3
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 122 deletions.
25 changes: 16 additions & 9 deletions src/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,26 @@ public function hasScope($scope = '')
* Obtain a valid access token for a scope.
*
* @param string $scope Access scope
* @param bool $scopeOnly If true, a token is requested just for the specified scope
*
* @return AccessToken New access token
*/
public function get($scope = '')
public function get($scope = '', $scopeOnly = false)
{
$url = $this->platform->accessTokenUrl;
if (!empty($url) && !empty(Tool::$defaultTool) && !empty(Tool::$defaultTool->rsaKey)) {
$scopesRequested = Tool::$defaultTool->requiredScopes;
if (substr($scope, -9) === '.readonly') {
$scope2 = substr($scope, 0, -9);
if ($scopeOnly) {
$scopesRequested = array($scope);
} else {
$scope2 = $scope;
}
if (!empty($scope) && !in_array($scope, $scopesRequested) && !in_array($scope2, $scopesRequested)) {
$scopesRequested[] = $scope;
$scopesRequested = Tool::$defaultTool->requiredScopes;
if (substr($scope, -9) === '.readonly') {
$scope2 = substr($scope, 0, -9);
} else {
$scope2 = $scope;
}
if (!empty($scope) && !in_array($scope, $scopesRequested) && !in_array($scope2, $scopesRequested)) {
$scopesRequested[] = $scope;
}
}
if (!empty($scopesRequested)) {
$retry = false;
Expand All @@ -174,7 +179,9 @@ public function get($scope = '')
$this->scopes = $scopesAccepted;
$this->token = $http->responseJson->access_token;
$this->expires = time() + $http->responseJson->expires_in;
$this->save();
if (!$scopeOnly) {
$this->save();
}
}
$retry = false;
} elseif ($retry) {
Expand Down
Loading

0 comments on commit e17cbb3

Please sign in to comment.