You are here

public function ApiAuthorize::authorize in FormAssembly 8

Use the auth code provided by FormAssembly to authorize the application.

Parameters

string $code: The authorization code returned by FormAssembly.

File

src/ApiAuthorize.php, line 70

Class

ApiAuthorize
Service class for FormAssembly API: Handles authorization.

Namespace

Drupal\formassembly

Code

public function authorize($code) {

  // Configure the request:
  $provider = $this
    ->getOauthProvider();

  // Try to get an access token using the authorization code grant.
  try {
    $accessToken = $provider
      ->getAccessToken('authorization_code', [
      'code' => $code,
    ]);
    $this->state
      ->set('fa_form.access_token', $accessToken);
  } catch (\Exception $e) {
    $this->logger
      ->critical('FormAssembly authorization request failed with Exception: %exception_type.', [
      '%exception_type' => get_class($e),
    ]);
  }
}