public function SalesforceOAuthController::oauthCallback in Salesforce Suite 8.4
Same name and namespace in other branches
- 5.0.x modules/salesforce_oauth/src/Controller/SalesforceOAuthController.php \Drupal\salesforce_oauth\Controller\SalesforceOAuthController::oauthCallback()
Pass-through to OAuth plugin.
1 string reference to 'SalesforceOAuthController::oauthCallback'
- salesforce_oauth.routing.yml in modules/
salesforce_oauth/ salesforce_oauth.routing.yml - modules/salesforce_oauth/salesforce_oauth.routing.yml
File
- modules/
salesforce_oauth/ src/ Controller/ SalesforceOAuthController.php, line 65
Class
- SalesforceOAuthController
- SalesforceOAuthController.
Namespace
Drupal\salesforce_oauth\ControllerCode
public function oauthCallback() {
if (empty($this->request
->get('code'))) {
throw new AccessDeniedHttpException();
}
$configId = $this->tempStore
->get('config_id');
if (empty($configId) || !($config = SalesforceAuthConfig::load($configId)) || !$config
->getPlugin() instanceof SalesforceAuthProviderInterface) {
$this->messenger
->addError($this
->t('No OAuth config found. Please try again.'));
return new RedirectResponse(Url::fromRoute('entity.salesforce_auth.collection')
->toString());
}
/** @var \Drupal\salesforce\SalesforceAuthProviderInterface $oauth */
$oauth = $config
->getPlugin();
if (\Drupal::request()
->get('code')) {
try {
$oauth
->requestAccessToken(\Drupal::request()
->get('code'));
$this
->messenger()
->addStatus($this
->t('Successfully connected to Salesforce.'));
return new RedirectResponse(Url::fromRoute('entity.salesforce_auth.collection')
->toString());
} catch (\Exception $e) {
$this
->messenger()
->addError($this
->t('Salesforce auth failed: @message', [
'@message' => $e
->getMessage() ?: get_class($e),
]));
}
}
else {
$this
->messenger()
->addError($this
->t('Salesforce auth failed: no oauth code received.'));
}
return new RedirectResponse(Url::fromRoute('entity.salesforce_auth.edit_form', [
'salesforce_auth' => $configId,
])
->toString());
}