You are here

public function OauthInteractions::code in FormAssembly 8

Capture the authorization code and trigger token request.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Redirect to the settings form.

Throws

\Exception Re-throws any caught exception after sending a message to the user.

1 string reference to 'OauthInteractions::code'
formassembly.routing.yml in ./formassembly.routing.yml
formassembly.routing.yml

File

src/Controller/OauthInteractions.php, line 98

Class

OauthInteractions
Utility class for interacting with FormAssembly for authorization.

Namespace

Drupal\formassembly\Controller

Code

public function code() {
  try {
    $code = $this->currentRequest->query
      ->get('code');
    if (empty($code)) {
      throw new \UnexpectedValueException("The authorization_code query parameter is missing.");
    }
    $this->apiAuthorize
      ->authorize($code);
    $this->messenger
      ->addMessage($this
      ->t('FormAssembly successfully authorized.'));
    $url = Url::fromRoute('fa_form.settings');
    return new RedirectResponse($url
      ->toString());
  } catch (\Exception $exception) {
    $this->messenger
      ->addMessage($this
      ->t('FormAssembly module failed to authorize. Reason: @message', [
      '@message' => $exception
        ->getMessage(),
    ]), 'error');
    throw $exception;
  }
}