forked from therealmarknelson/php_office365_cleintcred
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
78 lines (58 loc) · 2.08 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
<?php
session_start();
require_once('office365/init.php');
/**
* Enter your client id, secret key, thumbprint and redirect url below
*/
\Office365\Office365::setClientId('');
\Office365\Office365::setSecret('');
\Office365\Office365::setThumbprint('');
\Office365\Office365::setAuthorizationRedirectUrl('');
//sample pages
include('views/header.php');
switch($_SERVER['REQUEST_URI']) {
case '/consent':
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$id_token = $_POST['id_token'];
//request access token using id_token provided from authorization response
$access_token = new \Office365\AccessToken($id_token);
$get_access_token = $access_token->retrieve();
if ($get_access_token->access_token) {
// save the access token to the session
$_SESSION['access_token'] = $get_access_token->access_token;
echo '<br>Access token acquired: ';
echo $_SESSION['access_token'];
} else {
echo $get_access_token['error_description'];
}
}
break;
case '/mail':
include('views/form.php');
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
$user = $_POST['email'];
$access_token = $_SESSION['access_token'];
$mail = new \Office365\Mail();
$response = $mail->retrieve($user);
if ( isset($response->value) ) {
include('views/mail.php');
} else {
include('views/error.php');
}
}
break;
case '/calendar':
include('views/form.php');
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
$user = $_POST['email'];
$access_token = $_SESSION['access_token'];
$calendar = new \Office365\Calendar();
$response = $calendar->retrieve($user);
if ( isset($response->value) ) {
include('views/calendar.php');
} else {
include('views/error.php');
}
}
break;
}