Initial commit
This commit is contained in:
43
controllers/GoogleCallback.php
Normal file
43
controllers/GoogleCallback.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php namespace NicoSt\GCalendar\Controllers;
|
||||
|
||||
use Backend\Classes\Controller;
|
||||
use Input;
|
||||
use Log;
|
||||
use Lang;
|
||||
use Redirect;
|
||||
|
||||
use NicoSt\GCalendar\Models\Settings;
|
||||
use NicoSt\GCalendar\Classes\GoogleCalendarClient;
|
||||
|
||||
|
||||
class GoogleCallback extends Controller {
|
||||
|
||||
public function oauth2callback() {
|
||||
|
||||
$error = Input::get('error');
|
||||
$code = Input::get('code');
|
||||
|
||||
if (!empty($error)) {
|
||||
Log::error('G-Calendar: Error during authorization ['. $error .'].');
|
||||
die;
|
||||
}
|
||||
|
||||
if (!empty($code)) {
|
||||
Log::info('G-Calendar: Successfully authorized. Authentication code ['. $code .'].');
|
||||
|
||||
$class = new GoogleCalendarClient(false);
|
||||
$client = $class->getClient();
|
||||
|
||||
$accessToken = $client->fetchAccessTokenWithAuthCode($code);
|
||||
$client->setAccessToken($accessToken);
|
||||
|
||||
Log::info('G-Calendar: Set access-token ['. print_r($client->getAccessToken(), true) .'].');
|
||||
Settings::set('access_token', $client->getAccessToken());
|
||||
|
||||
return Redirect::to('/backend/system/settings/update/nicost/gcalendar/settings');
|
||||
}else {
|
||||
Log::error('G-Calendar: Invalid callback request. Expected "code" or "error" param missing.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user