You are here

public function OauthController::authFinish in Media: Acquia DAM 8

Finish the authentication process.

Route: /acquiadam/authFinish.

1 string reference to 'OauthController::authFinish'
media_acquiadam.routing.yml in ./media_acquiadam.routing.yml
media_acquiadam.routing.yml

File

src/Controller/OauthController.php, line 193

Class

OauthController
Controller routines for acquiadam routes.

Namespace

Drupal\media_acquiadam\Controller

Code

public function authFinish() {
  $authFinishRedirect = $this->request->query
    ->get('auth_finish_redirect');
  if ($original_path = $this->request->query
    ->get('original_path', FALSE)) {
    $authFinishRedirect .= '&original_path=' . $original_path;
  }
  $this->oauth
    ->setAuthFinishRedirect($authFinishRedirect);
  if (!$this->oauth
    ->authRequestStateIsValid($this->request
    ->get('state'))) {
    throw new AccessDeniedHttpException();
  }
  $access_token = $this->oauth
    ->getAccessToken($this->request
    ->get('code'));
  $this->userData
    ->set('media_acquiadam', $this->currentUser
    ->id(), 'acquiadam_access_token', $access_token['access_token']);
  $this->userData
    ->set('media_acquiadam', $this->currentUser
    ->id(), 'acquiadam_access_token_expiration', $access_token['expire_time']);
  $this->userData
    ->set('media_acquiadam', $this->currentUser
    ->id(), 'acquiadam_refresh_token', $access_token['refresh_token']);
  return new RedirectResponse($authFinishRedirect);
}