You are here

public function Callback::callbackUrl in Instagram API 8

Callback URL for Instagram Auth.

1 string reference to 'Callback::callbackUrl'
instagram_api.routing.yml in ./instagram_api.routing.yml
instagram_api.routing.yml

File

src/Controller/Callback.php, line 57

Class

Callback
Class Instagram Callback Controller.

Namespace

Drupal\instagram_api\Controller

Code

public function callbackUrl(Request $request) {

  // TODO
  // Add a secure hash param to the previous request
  // And validate on return if this hash is valid.
  $code = $request
    ->get('code');

  // Try to get the token.
  $token = $this
    ->getToken($code);

  // If token is not empty.
  if ($token != FALSE) {

    // Save the token.
    $this->configEditable
      ->set('access_token', $token)
      ->save();
    $markup = $this
      ->t("Access token saved");
  }
  else {
    $markup = $this
      ->t("Failed to get access token. Check log messages.");
  }
  return [
    '#markup' => $markup,
  ];
}