Перенаправление на сервер Google OAuth 2.0 не перенаправляет - PullRequest
0 голосов
/ 09 мая 2019

У меня есть клиентская часть jquery, которая вызывает функцию php, которая должна войти в Google oauth. Перенаправление, исходящее от серверной части, не работает, и я получаю ошибку cors в консоли.

Я перепробовал практически все, что мог придумать, установив заголовки как переднего, так и заднего конца, но ничто не позволяет странице перенаправлять. если я буду следовать URL-адресу, который выводится на консоль, ошибка сработает, если я нажму на нее и смогу продолжить вход.

$("#authorize_button").on('click', function(){
  console.log('this is firing');
$.get('/googlecalendars/signin', function(data){
    console.log('return data  ', data);
  }, 'json');
})

, а затем для задней части

  function signIn($f3){
  $client = $this->getGoogleClient($f3);
  error_log('this is the client.    '.print_r($client,true));

  $service = new Google_Service_Calendar($client);
    // Print the next 10 events on the user's calendar.
    $calendarId = 'primary';
    $optParams = array(
      'maxResults' => 10,
      'orderBy' => 'startTime',
      'singleEvents' => true,
      'timeMin' => date('c'),
    );
    $results = $service->events->listEvents($calendarId, $optParams);
    $events = $results->getItems();
    // die(json_encode(['status' => 1, 'results' => $results ]));

  }
  function getGoogleClient($f3){

  error_log(' > Getting client for the calendar');

  require_once 'vendor/autoload.php';

  $client = new Google_Client();
  $client->setApplicationName(' Google Calendar');

  $client->setScopes(array('https://www.googleapis.com/auth/calendar.readonly'));
  #$client->setScopes(Google_Service_Drive::DRIVE_FILE);

  $client->setClientId('425816667494-8btgu9aasfwefewferfo8.apps.googleusercontent.com'); 
  $client->setClientSecret('6negererger4r34r34');

  $client->setRedirectUri(SELF::BASEURL.'/googlecalendars/signin');

  $client->setAccessType("offline");
  $client->setApprovalPrompt('force');

  $token = false;

  if(isset($f3->get('account')['apps']['googlecalendar'])){
    error_log('we have the first part ');
    $gc = $f3->get('account')['apps']['googlecalendar']['token'];
    error_log('this is the gc  '.print_r($gc,true));
    if(isset($gc)){
    error_log('you have the token  ');
        $token = $gc;
    }
  }

  if(!$token && !$f3->get('GET.code')) {
      #go get fresh auth code..
      $authUrl = $client->createAuthUrl();
      header('Location: '.$authUrl); 
      exit;
  }

есть еще одна функция, которая отлично работает и возвращает клиента. но это именно последняя строка, которая не работает. Однако, если я объединю функции в одну и буду запускать их каждый раз, когда пользователь переходит к конечной точке, это будет работать.

Если вам нужна дополнительная информация, пожалуйста, дайте мне знать.

...