-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
86 lines (76 loc) · 2.1 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
ini_set('display_errors', 1);
session_start();
require_once 'vendor/autoload.php';
require_once 'kpasinc/dataporten.inc';
require_once 'kpasinc/vars.inc';
require_once 'kpasinc/canvas.inc';
require_once 'kpasinc/utility.inc';
if(isset($_GET['logout'])) {
session_destroy();
header('HTTP/1.1 302 Found');
header('Location: https://auth.dataporten.no/logout');
}
use Kasperrt\OAuth2;
$oauth2 = null;
$initialized = false;
$userInfo = "";
$minegrupper = false;
if(isset($_GET['minegrupper'])) {
$minegrupper = true;
$_SESSION["minegrupper"] = true;
}
else if(isset($_SESSION['minegrupper'])){
$minegrupper = true;
}
else if(isset($_GET['course_id'])) {
$course_id = $_GET['course_id'];
$_SESSION["courseId"] = $course_id;
}
else if(!isset($_SESSION["courseId"]))
{
echo "Mangler course_id parameter.";
printLogoutButton();
exit;
}
$oauth2 = new OAuth2([
"client_id" => $client_id,
"client_secret" => $client_secret,
"redirect_uri" => $redirect_uri,
"auth" => "https://auth.dataporten.no/oauth/authorization",
"token" => "https://auth.dataporten.no/oauth/token",
"response_type" => "code",
"session" => true
]);
if(isset($_GET['code'])) {
$code = $_GET['code'];
$state = $_GET['state'];
mydbg("Code:" . $code);
mydbg("State:" . $state);
mydbg("Getting access token...");
$access_token = $oauth2->get_access_token($state, $code);
mydbg($access_token);
$_SESSION["token"] = $access_token;
$userInfo = getUserInfoFromDataporten($access_token, $oauth2);
$groupsInfo = getGroupsInfoFromDataporten($access_token, $oauth2);
$extraUserInfo = getExtraUserInfoFromDataporten($access_token, $oauth2);
$initialized = true;
}else {
$oauth2->redirect();
}
if($initialized)
{
$_SESSION["userInfo"] = $userInfo;
$_SESSION["groups"] = $groupsInfo;
$_SESSION["extraUserInfo"] = $extraUserInfo;
if($minegrupper)
{
mydbg("Minegrupper is true");
header('Location: minegrupper.php');
}
else
{
header('Location: worker.php');
}
}
?>