<meta charset="utf-8" /> <title></title> <link rel="stylesheet" href="<?php echo TRUSTED_LOGIN_PLUGIN_PATH; ?> css/tlogin-2.0.2.css"> <link rel="stylesheet" href="css/main.css"> </head> <body> <div class="page"> <h1>Тестовая страница Trusted.Login </h1> <?php // session_unset(); $token = OAuth2::getFromSession(); //Получаем токен if ($token) { $user = $token->getUser(); $suser = $user->getServiceUser(); echo "<div class='view-contaier'>"; echo "<div class='profile'>"; echo "<div style='width: 50px; height: 50px; border-radius: 100%; background: url(" . $suser->getAvatarUrl($token->getAccessToken()) . ") no-repeat; background-size: contain; display: inline-block'></div>"; echo "<span class='user-name'>" . $suser->getDisplayName() . "</span>"; echo "<a class='view-login' href='logout.php'>Выход</a>"; echo "</div>"; echo "</div>"; } else { // Вставка виджета Trusted.Login include './tlogin.tpl'; }
/** * Возвращает данные о пользователе полученные с сервиса. * @return \ServiceUser * @throws OAuth2Exception */ function getServiceUser() { $res = $this->serviceUser; if (!$res && $this->id) { $token = OAuth2::getFromSession(); if ($token) { $arUser = TAuthCommand::getUserProfileByToken($token->getAccessToken()); //Проверка идентификаторов пользователей //debug($arUser); if ($arUser['id'] == $this->id) { $res = ServiceUser::fromArray($arUser); } else { throw new OAuth2Exception(TRUSTEDNET_ERROR_MSG_DIFFERENT_USER_ID, TRUSTEDNET_ERROR_CODE_DIFFERENT_USER_ID, null); } } else { throw new OAuth2Exception(TRUSTEDNET_ERROR_MSG_TOKEN_NOT_FOUND, TRUSTEDNET_ERROR_CODE_TOKEN_NOT_FOUND, null); } } return $res; }
static function token($params) { $res = array("success" => true, "message" => ""); try { $token = OAuth2::getFromSession(); //$refreshToken = $token->getRefreshToken(); //$token->refresh(); $accessToken = $token->getAccessToken(); $res["message"] = $accessToken; } catch (OAuth2Exception $ex) { header("HTTP/1.1 500 Internal Server Error"); $res["message"] = $ex->message; echo json_encode($res); die; } return $res; }