2021-07-27 10:16:10 +02:00
|
|
|
<?php
|
2021-09-23 17:13:19 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
|
|
|
* Copyright (C) DevCode s.r.l.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-07-27 10:16:10 +02:00
|
|
|
|
2021-09-23 17:13:19 +02:00
|
|
|
use Models\OAuth2;
|
2021-07-27 10:16:10 +02:00
|
|
|
|
|
|
|
$skip_permissions = true;
|
|
|
|
include_once __DIR__.'/core.php';
|
|
|
|
session_write_close();
|
|
|
|
|
|
|
|
// Authorization information
|
|
|
|
$state = $_GET['state'];
|
|
|
|
$code = $_GET['code'];
|
|
|
|
|
2021-09-23 17:13:19 +02:00
|
|
|
// Account individuato via state
|
2021-07-27 10:16:10 +02:00
|
|
|
if (!empty($state)) {
|
2021-09-23 17:13:19 +02:00
|
|
|
$account = OAuth2::where('state', '=', $state)
|
2021-07-27 10:16:10 +02:00
|
|
|
->first();
|
|
|
|
} else {
|
2021-09-23 17:13:19 +02:00
|
|
|
$account = OAuth2::find(get('id'));
|
2021-07-27 10:16:10 +02:00
|
|
|
|
|
|
|
// Impostazione access token a null per reimpostare la configurazione
|
|
|
|
$account->access_token = null;
|
2021-07-27 14:49:18 +02:00
|
|
|
$account->refresh_token = null;
|
2021-07-27 10:16:10 +02:00
|
|
|
$account->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($account)) {
|
|
|
|
echo tr('Errore durante il completamento della configurazione: account non trovato');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect all'URL di autorizzazione del servizio esterno
|
2024-01-26 17:00:02 +01:00
|
|
|
$response = $account->configure($code, $state);
|
2021-07-27 10:16:10 +02:00
|
|
|
|
|
|
|
// Redirect automatico al record
|
2024-01-26 17:00:02 +01:00
|
|
|
if (empty($response['authorization_url'])) {
|
2021-09-23 17:13:19 +02:00
|
|
|
$redirect = $account->after_configuration;
|
2024-01-26 17:00:02 +01:00
|
|
|
} else {
|
|
|
|
$redirect = $response['authorization_url'];
|
2021-07-27 10:16:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($_GET['error'])) {
|
|
|
|
redirect($redirect);
|
2024-01-15 15:30:45 +01:00
|
|
|
exit;
|
2021-07-27 10:16:10 +02:00
|
|
|
} else {
|
2023-07-20 12:12:27 +02:00
|
|
|
echo strip_tags($_GET['error']).'<br>'.strip_tags($_GET['error_description']).'
|
2021-07-27 10:16:10 +02:00
|
|
|
<br><br>
|
|
|
|
<a href="'.$redirect.'">'.tr('Riprova').'</a>';
|
|
|
|
}
|