Skip to content

Commit

Permalink
Do not throw an error when configuring token for the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed May 4, 2023
1 parent 2e911bb commit 7016a8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CRM/Civixero/Form/XeroAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public function preProcess(): void {
}
}
}
catch (CRM_Core_Exception $e) {
// Token not yet configured.
}
catch (IdentityProviderException $e) {
// Expected invalid_grant. Continue to let user authorize.
}
Expand Down
7 changes: 6 additions & 1 deletion CRM/Civixero/OAuth2/Xero.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public static function singleton($connector_id = 0, $client_id = '', $client_sec
}

public function __construct($accessToken, $client_id, $client_secret, $tenant_id, $connector_id) {
$this->store = new CRM_Civixero_OAuth2_TokenStoreDefault($accessToken, $connector_id);
if ($accessToken['access_token']) {
$this->store = new CRM_Civixero_OAuth2_TokenStoreDefault($accessToken, $connector_id);
}
$this->tenantID = $tenant_id;
$this->connectorID = $connector_id;
$this->redirectURL = CRM_Utils_System::url('civicrm/xero/authorize',
Expand Down Expand Up @@ -109,6 +111,9 @@ public function __construct($accessToken, $client_id, $client_secret, $tenant_id
* @throws \League\OAuth2\Client\Provider\Exception\IdentityProviderException
*/
public function getToken(): AccessTokenInterface {
if (!$this->store) {
throw new CRM_Core_Exception('No token configured.');
}
$accessToken = $this->store->fetch();
if (!$accessToken) {
throw new CRM_Core_Exception('No token in store.');
Expand Down

0 comments on commit 7016a8c

Please sign in to comment.