Ejemplo n.º 1
0
 public static function checkResponseAndRefreshToken($response)
 {
     if ($response['errorNumber'] && $response['errorNumber'] == 401) {
         error_log("Request returned 401, attempting to refresh token.");
         // Use the refresh token to get a new token and update session variables.
         $newTokenInfo = Office365Service::getTokenFromRefreshToken($_SESSION['refreshToken']);
         if ($newTokenInfo['access_token']) {
             $_SESSION['accessToken'] = $newTokenInfo['access_token'];
             $_SESSION['refreshToken'] = $newTokenInfo['refresh_token'];
             error_log("Retrieved new token and updated session variables.");
             return true;
         }
         error_log("No access token returned.");
         return false;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
}
if (is_array($eventId) && $eventId['error']) {
    $msg = "Error adding event to calendar: " . $eventId['error'];
    error_log($msg);
    header("Location: " . $errorPage . "?errorMsg=" . urlencode($msg));
    exit;
}
// If a voucher is required, add it as an attachment to the event.
if ($event->voucherRequired) {
    $attachmentData = "This is your voucher for '" . $event->title . "' on " . date_format($event->startTime, "M j, Y");
    $result = Office365Service::addAttachmentToEvent($accessToken, $eventId, $attachmentData);
    if (SessionManager::checkResponseAndRefreshToken($result)) {
        // Pick up new access token
        $accessToken = $_SESSION['accessToken'];
        // Retry request
        $result = Office365Service::addAttachmentToEvent($accessToken, $eventId, $attachmentData);
    }
    if ($result['error']) {
        $msg = "Error adding attachment to event: " . $result['error'];
        error_log($msg);
        header("Location: " . $errorPage . "?errorMsg=" . urlencode($msg));
        exit;
    }
}
// Finally, redirect the user back to the home page.
header("Location: " . $homePage);
/*
 MIT License: 
 
 Permission is hereby granted, free of charge, to any person obtaining 
 a copy of this software and associated documentation files (the 
Ejemplo n.º 3
0
<!-- Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file. -->
<?php 
// create an array to set page-level variables
$page = array();
$page['title'] = 'Home';
// include the page header
include 'common/header.php';
require 'o365/Office365Service.php';
// Check if there is user info in the session.
$loggedIn = !is_null($_SESSION['userName']);
// If the user is not logged in, the buttons will not say "Add to Calendar", but will
// instead say "Connect to my Calendar".
if (!$loggedIn) {
    $redirectUri = "http" . ($_SERVER["HTTPS"] == "on" ? "s://" : "://") . $_SERVER["HTTP_HOST"] . "/php-calendar/o365/authorize.php";
    $loginUrl = Office365Service::getLoginUrl($redirectUri);
}
?>

<h1>Welcome to php-calendar!</h1>
<div>Here are the upcoming shows for our Shakespearean Festival.</div>
<div><span id="table-title">Upcoming Shows</span></div>
<table class="show-list">
  <tr>
    <th class="button"></th>
    <th>Performance</th>
    <th>Location</th>
    <th>Voucher Required?</th>
    <th>Date</th>
    <th>Start</th>
    <th>End</th>
  </tr>
Ejemplo n.º 4
0
    exit;
} else {
    error_log("authorize.php called with code: " . $code);
    $redirectUri = "http" . ($_SERVER["HTTPS"] == "on" ? "s://" : "://") . $_SERVER["HTTP_HOST"] . "/php-calendar/o365/authorize.php";
    error_log("Calling getTokenFromAuthCode");
    // Use the code supplied by Azure to request an access token.
    $tokens = Office365Service::getTokenFromAuthCode($code, $redirectUri);
    if ($tokens['access_token']) {
        error_log("getTokenFromAuthCode returned:");
        error_log("  access_token: " . $tokens['access_token']);
        error_log("  refresh_token: " . $tokens['refresh_token']);
        // Save the access token and refresh token to the session.
        $_SESSION['accessToken'] = $tokens['access_token'];
        $_SESSION['refreshToken'] = $tokens['refresh_token'];
        // Parse the id token returned in the response to get the user name.
        $_SESSION['userName'] = Office365Service::getUserName($tokens['id_token']);
        // Redirect back to the homepage.
        $homePage = "http" . ($_SERVER["HTTPS"] == "on" ? "s://" : "://") . $_SERVER["HTTP_HOST"] . "/php-calendar/home.php";
        header("Location: " . $homePage);
        exit;
    } else {
        $msg = "Error retrieving access token: " . $tokens['error'];
        error_log($msg);
        header("Location: " . $errorPage . "?errorMsg=" . urlencode($msg));
    }
}
/*
 MIT License: 
 
 Permission is hereby granted, free of charge, to any person obtaining 
 a copy of this software and associated documentation files (the 
Ejemplo n.º 5
0
// Get the index of the show from the query parameters
$showIndex = $_GET['showIndex'];
error_log("addToCalendar.php called.");
error_log("showIndex parameter: " . $showIndex);
// Get access token from the session.
$accessToken = $_SESSION['accessToken'];
// Get the event from the array of events in the session.
$event = $_SESSION['events'][$showIndex];
error_log("Retrieved event '" . $event->title . "' from session.");
// Get all events on the user's O365 calendar for that day.
$eventsOnThisDay = Office365Service::getEventsForDate($accessToken, $event->startTime);
if (SessionManager::checkResponseAndRefreshToken($eventsOnThisDay)) {
    // Pick up new access token
    $accessToken = $_SESSION['accessToken'];
    error_log("Retrying get events request");
    $eventsOnThisDay = Office365Service::getEventsForDate($accessToken, $event->startTime);
}
// Build a link URL to the doAdd.php file, which does the actual work to add
// the event to the O365 calendar.
$buttonUrl = "doAdd.php";
$altRow = false;
?>

<div id="content">
  <div id="event-details">
    <h1>Add Event To Calendar</h1>
    <table>
      <tr>
        <td>Show</td>
        <td><?php 
echo $event->title;
Ejemplo n.º 6
0
<?php

// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
session_start();
require 'o365/Office365Service.php';
// Clear user info from the session.
unset($_SESSION['userName']);
unset($_SESSION['accessToken']);
unset($_SESSION['refreshToken']);
// Build a URL back to the homepage.
$redirectUri = "http" . ($_SERVER["HTTPS"] == "on" ? "s://" : "://") . $_SERVER["HTTP_HOST"] . "/php-calendar/home.php";
// Redirect the user to the Azure logout URL, which will then redirect back to the homepage.
header("Location: " . Office365Service::getLogoutUrl($redirectUri));
/*
 MIT License: 
 
 Permission is hereby granted, free of charge, to any person obtaining 
 a copy of this software and associated documentation files (the 
 ""Software""), to deal in the Software without restriction, including 
 without limitation the rights to use, copy, modify, merge, publish, 
 distribute, sublicense, and/or sell copies of the Software, and to 
 permit persons to whom the Software is furnished to do so, subject to 
 the following conditions: 
 
 The above copyright notice and this permission notice shall be 
 included in all copies or substantial portions of the Software. 
 
 THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE