Skip to content
Snippets Groups Projects
Commit 86156ba2 authored by Janega Zoltán's avatar Janega Zoltán
Browse files

remove unneccesary parts

parent d695a092
No related branches found
No related tags found
No related merge requests found
<?php
class AuthSCHClient {
class AuthSCHClient
{
private static $host = "https://auth.sch.bme.hu/";
private static $username = ""; // your application's id
......@@ -9,7 +10,8 @@ class AuthSCHClient {
private $tokens;
public function __construct($tokens = null) {
public function __construct($tokens = null)
{
$this->tokens = new \stdClass();
if ($tokens === null) {
......@@ -42,19 +44,19 @@ class AuthSCHClient {
}
}
public function __destruct() {
public function __destruct()
{
if (isset($this->tokens)) {
unset ($this->tokens);
}
}
private function curlExec($urlPart, $data) {
private function curlExec($urlPart, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::$host . $urlPart);
curl_setopt($ch, CURLOPT_HEADER, 0);
if($urlPart != "oauth2/resource") {
curl_setopt($ch, CURLOPT_USERPWD, self::$username . ":" . self::$password);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
......@@ -64,30 +66,11 @@ class AuthSCHClient {
return $ret;
}
private function authenticate() {
private function authenticate()
{
// before authentication & authorization
if (!isset($_GET['code'])) {
// get token
$data = array(
'grant_type' => 'client_credentials',
);
$ch = $this->curlExec("oauth2/token", $data);
$data = array(
'access_token' => json_decode($ch)->access_token,
);
$ch = $this->curlExec("oauth2/resource", $data);
$res = json_decode($ch);
// check api access & redirect to auth.sch.bme.hu for authorization
if ($res != null && isset($res->success) && $res->success == true) {
header("Location: " . self::$host . "site/login?response_type=code&client_id=" . self::$username . "&state=" . sha1($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']) . "&scope=" . self::$scope);
die();
} else {
throw new Exception("error during api check");
}
} else {
$data = array(
'grant_type' => 'authorization_code',
......@@ -105,7 +88,8 @@ class AuthSCHClient {
}
private function reauthenticate() {
private function reauthenticate()
{
$data = array(
'grant_type' => 'refresh_token',
'refresh_token' => $this->tokens->refresh_token,
......@@ -120,7 +104,8 @@ class AuthSCHClient {
$this->tokens->access_token = $tokens->access_token;
}
public function getData() {
public function getData()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::$host . 'api/profile/?access_token=' . $this->tokens->access_token);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment