Skip to content
Snippets Groups Projects
Commit 9bfd9e75 authored by Aaron Bauman's avatar Aaron Bauman Committed by Aaron Bauman
Browse files

Issue #3191597 by AaronBauman, VladimirAus: POST...

Issue #3191597 by AaronBauman, VladimirAus: POST https://login.salesforce.com/id/...` resulted in a `403 Forbidden` response: Bad_OAuth_Token
parent fe4ab949
No related branches found
No related tags found
No related merge requests found
...@@ -141,7 +141,7 @@ class SalesforceAuthForm extends EntityForm { ...@@ -141,7 +141,7 @@ class SalesforceAuthForm extends EntityForm {
$this->entity->getPlugin()->submitConfigurationform($form, $form_state); $this->entity->getPlugin()->submitConfigurationform($form, $form_state);
// If redirect is not already set, and we have no errors, send user back to // If redirect is not already set, and we have no errors, send user back to
// the AuthConfig listing page. // the AuthConfig listing page.
if (!$form_state->getErrors() && !$form_state->getRedirect()) { if (!$form_state->getErrors() && !$form_state->getResponse() && !$form_state->getRedirect()) {
$form_state->setRedirectUrl($this->entity->toUrl('collection')); $form_state->setRedirectUrl($this->entity->toUrl('collection'));
} }
} }
......
...@@ -5,6 +5,7 @@ namespace Drupal\salesforce; ...@@ -5,6 +5,7 @@ namespace Drupal\salesforce;
use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerTrait; use Drupal\Core\Messenger\MessengerTrait;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\salesforce\Storage\SalesforceAuthTokenStorageInterface; use Drupal\salesforce\Storage\SalesforceAuthTokenStorageInterface;
use OAuth\Common\Http\Client\ClientInterface; use OAuth\Common\Http\Client\ClientInterface;
...@@ -171,6 +172,13 @@ abstract class SalesforceAuthProviderPluginBase extends Salesforce implements Sa ...@@ -171,6 +172,13 @@ abstract class SalesforceAuthProviderPluginBase extends Salesforce implements Sa
* {@inheritdoc} * {@inheritdoc}
*/ */
public function save(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) {
if ($form_state->getResponse() instanceof TrustedRedirectResponse) {
// If we're redirecting off-site, do not proceed with save operation.
// We'll finish saving form input when we complete the OAuth handshake
// from Salesforce.
return FALSE;
}
// Initialize identity if token is available. // Initialize identity if token is available.
if (!$this->hasAccessToken()) { if (!$this->hasAccessToken()) {
return TRUE; return TRUE;
...@@ -181,7 +189,14 @@ abstract class SalesforceAuthProviderPluginBase extends Salesforce implements Sa ...@@ -181,7 +189,14 @@ abstract class SalesforceAuthProviderPluginBase extends Salesforce implements Sa
'Content-type' => 'application/json', 'Content-type' => 'application/json',
]; ];
$data = $token->getExtraParams(); $data = $token->getExtraParams();
$response = $this->httpClient->retrieveResponse(new Uri($data['id']), [], $headers); try {
$response = $this->httpClient->retrieveResponse(new Uri($data['id']), [], $headers);
}
catch (\Exception $e) {
$this->messenger()->addError($e->getMessage());
$form_state->disableRedirect();
return FALSE;
}
$identity = $this->parseIdentityResponse($response); $identity = $this->parseIdentityResponse($response);
$this->storage->storeIdentity($this->service(), $identity); $this->storage->storeIdentity($this->service(), $identity);
return TRUE; return TRUE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment