8 require_once( CH_DIRECTORY_PATH_INC .
'profiles.inc.php' );
30 parent::_actionAdministration(
'ch_dolphcon_api_key',
'_ch_dolphcon_settings',
'_ch_dolphcon_information',
'_ch_dolphcon_information_block');
41 $this->
_redirect ($this -> _oConfig -> sDefaultRedirectUrl);
43 if (!$this->_oConfig->sApiID || !$this->_oConfig->sApiSecret || !$this->_oConfig->sApiUrl) {
45 $this->_oTemplate->getPage(
_t(
'_ch_dolphcon'),
$sCode);
51 'response_type' =>
'code',
52 'client_id' => $this->_oConfig->sApiID,
53 'redirect_uri' => $this->_oConfig->sPageHandle,
54 'scope' => $this->_oConfig->sScope,
55 'state' => $this->_genCsrfToken(),
65 $this->_oTemplate->getPage(
_t(
'_Error'),
MsgBox(
_t(
'_ch_dolphcon_state_invalid')));
72 $sErrorDescription =
ch_get(
'error_description') ?
ch_get(
'error_description') :
_t(
'_Error occured');
73 $this->_oTemplate->getPage(
_t(
'_Error'),
MsgBox($sErrorDescription));
79 'client_id' => $this->_oConfig->sApiID,
80 'client_secret' => $this->_oConfig->sApiSecret,
81 'grant_type' =>
'authorization_code',
83 'redirect_uri' => $this->_oConfig->sPageHandle,
87 if (!
$s || NULL === ($aResponse = json_decode(
$s,
true)) || !isset($aResponse[
'access_token']) || isset($aResponse[
'error'])) {
88 $sErrorDescription = isset($aResponse[
'error_description']) ? $aResponse[
'error_description'] :
_t(
'_Error occured');
89 $this->_oTemplate->getPage(
_t(
'_Error'),
MsgBox($sErrorDescription));
94 $sAccessToken = $aResponse[
'access_token'];
95 $sExpiresIn = $aResponse[
'expires_in'];
96 $sExpiresAt = new \DateTime(
'+' . $sExpiresIn .
' seconds');
97 $sRefreshToken = $aResponse[
'refresh_token'];
101 'Authorization: Bearer ' . $sAccessToken,
105 if (!
$s || NULL === ($aResponse = json_decode(
$s,
true)) || !$aResponse || isset($aResponse[
'error'])) {
106 $sErrorDescription = isset($aResponse[
'error_description']) ? $aResponse[
'error_description'] :
_t(
'_Error occured');
107 $this->_oTemplate->getPage(
_t(
'_Error'),
MsgBox($sErrorDescription));
111 $aRemoteProfileInfo = $aResponse;
113 if ($aRemoteProfileInfo) {
116 $iLocalProfileId = $this->_oDb->getProfileId($aRemoteProfileInfo[
'id']);
118 if ($iLocalProfileId) {
123 $this->
setLogged($iLocalProfileId, $aLocalProfileInfo[
'Password']);
128 $sAlternativeNickName =
'';
129 if (
getID($aRemoteProfileInfo[
'NickName']))
134 $this->
_createProfile($aRemoteProfileInfo, $sAlternativeNickName);
138 $this->_oTemplate->getPage(
_t(
'_Error'),
MsgBox(
_t(
'_ch_dolphcon_profile_error_info')));
151 $aProfileFields[
'NickName'] =
$aProfileInfo[
'NickName'] . $sAlternativeName;
152 return $aProfileFields;
157 if (
$GLOBALS[
'MySQL']->
getParam(
'sys_security_form_token_enable') !=
'on' || defined(
'CH_WSB_CRON_EXECUTE'))
162 $iCsrfTokenLifetime = (int)$this->_oDb->getParam(
'sys_security_form_token_lifetime');
163 if ($oSession->getValue(
'ch_dolphcon_csrf_token') ===
false || ($iCsrfTokenLifetime != 0 &&
time() - (int)$oSession->getValue(
'csrf_token_time') > $iCsrfTokenLifetime)) {
165 $oSession->setValue(
'ch_dolphcon_csrf_token',
$sToken);
166 $oSession->setValue(
'ch_dolphcon_csrf_token_time',
time());
169 $sToken = $oSession->getValue(
'ch_dolphcon_csrf_token');
178 return $oSession->getValue(
'ch_dolphcon_csrf_token');