Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to authenticate with SharePoint Online for a PHP app?

We have our PHP application that requires authentication, and for our clients that run SharePoint we'd like to offer some kind of SSO service, so that the users can use their SharePoint credentials (we did something similar with Google Apps, CAS, ...)

Note: Obviously, our app is not hosted on the same domain/premices as SharePoint

I can't find the litterature about it, so any pointer would be welcome !

NB: we'd like to implement a proper tier authentification mechanism, so that the user can log into our app directly by typing the URL, and choose to login using SharePoint, exactly like you'd do with OAuth and the like...

Thanks in advance !

like image 204
Bertrand Gorge Avatar asked Aug 17 '12 12:08

Bertrand Gorge


1 Answers

SharePoint Online (SPO) supports claims based authentication.

The below picture demonstrates how authentication is performed in SPO:

enter image description here

According to this post the authentication process consists of the following steps:

Steps:

  1. Send SAML Request to STS
  2. Receive SAML Response
  3. Send the Security Token to SharePoint Online
  4. Receive the authentication cookies
  5. Send requests including authentication cookies

phpSPO - SharePoint client for PHP supports SPO authentication.

The library provides a SharePoint Online (SPO) client for PHP applications. It allows you to performs CRUD operations on SharePoint data using an SharePoint 2013 REST/OData based API.

Examples

How to perform authentication in SharePoint Online (SPO):

try {
    $client = new SPOClient($url);
    $client->signIn($username,$password);
    echo 'You have authenticated successfully\n';
}
catch (Exception $e) {
    echo 'Authentication failed: ',  $e->getMessage(), "\n";
}

The following examples demonstrates how to perform CRUD operations on SharePoint list data:

<?php
 
require_once 'SPOClient.php';
 
$username = '[email protected]';
$password = 'password';
$url = "https://tenant.sharepoint.com/";
 
$client = new SPOClient($url);
$client->signIn($username,$password);
 
//Get Tasks list
$listTitle = 'Tasks';
$list = $client->getList($listTitle);
    
//Create a Task item
$itemProperties = array('Title' => 'Order Approval', 'Body' => 'Order approval task');
$taskItem = $list->addItem($itemProperties);
print "Task '{$taskItem->Title}' has been created succesfully.\r\n";
 
$itemId = $taskItem->Id;
//Update a Task item
$itemProperties = array('PercentComplete' => 1);
$list->updateItem($itemId,$itemProperties);
 
//Delete a Task item
$list->deleteItem($itemId);
 
?>

References

SharePoint Online client for PHP

like image 143
Vadim Gremyachev Avatar answered Oct 16 '22 15:10

Vadim Gremyachev