forked from jasonhoekstra/slc-classview-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
50 lines (35 loc) · 1.57 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
<?php
session_start();
const CLIENT_ID = 'your_application_client_id';
const CLIENT_SECRET = 'your_application_client_secret';
const REDIRECT_URI = 'http://localhost/slc/index.php';
const AUTHORIZATION_ENDPOINT = 'https://api.sandbox.slcedu.org/api/oauth/authorize';
const TOKEN_ENDPOINT = 'https://api.sandbox.slcedu.org/api/oauth/token';
// If the session verification code is not set, redirect to the SLC Sandbox authorization endpoint
if (!isset($_GET['code'])) {
$url = 'https://api.sandbox.slcedu.org/api/oauth/authorize?client_id=' . CLIENT_ID . '&redirect_uri=' . REDIRECT_URI;
header('Location: ' . $url);
die('Redirect');
} else {
session_start();
$url = 'https://api.sandbox.slcedu.org/api/oauth/token?client_id=' . CLIENT_ID . '&client_secret=' . CLIENT_SECRET . '&grant_type=authorization_code&redirect_uri='.REDIRECT_URI.'&code='. $_GET['code'];
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 'Content-Type: application/vnd.slc+json');
curl_setopt($ch, CURLOPT_HEADER, 'Accept: application/vnd.slc+json');
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
// de-serialize the result into an object
$result = json_decode($result);
// set the session with the access_token and verification code
$_SESSION['access_token'] = $result->access_token;
$_SESSION['code'] = $_GET['code'];
// redirect to the start page of the application
header('Location: ' . 'start.php');
}
?>