vgrem / phpSPO

Microsoft 365 Library for PHP.
MIT License
360 stars 117 forks source link

Microsoft has closed basic authentication #302

Closed BeginnerRaffe closed 1 year ago

BeginnerRaffe commented 2 years ago

Hello All,

Microsoft has closed basic authentication. My authentication does not work anymore!!

What do I do? How can I solve it? Are there any solution for this?

I hope anybody could help me!!

BeginnerRaffe commented 2 years ago

I use this instead:

$credentials = new ClientCredential("{client-id}", "{client-secret}"); $client = (new ClientContext("https://{your-tenant-prefix}.sharepoint.com"))->withCredentials($credentials);

$web = $client->getWeb(); $list = $web->getLists()->getByTitle("{list-title}"); //init List resource $items = $list->getItems(); //prepare a query to retrieve from the $client->load($items); //save a query to retrieve list items from the server $client->executeQuery(); //submit query to SharePoint server

But I get this error: /What could that be?)

Fatal error: Uncaught Office365\Runtime\Http\RequestException in C:\xampp\htdocs\vendor\vgrem\php-spo\src\Runtime\ClientRequest.php:217 Stack trace: #0 C:\xampp\htdocs\vendor\vgrem\php-spo\src\Runtime\ClientRequest.php(173): Office365\Runtime\ClientRequest->validate(Object(Office365\Runtime\Http\Response)) #1 C:\xampp\htdocs\vendor\vgrem\php-spo\src\Runtime\OData\ODataRequest.php(142): Office365\Runtime\ClientRequest->executeQueryDirect(Object(Office365\Runtime\Http\RequestOptions)) #2 C:\xampp\htdocs\vendor\vgrem\php-spo\src\Runtime\ClientRequest.php(152): Office365\Runtime\OData\ODataRequest->executeQueryDirect(Object(Office365\Runtime\Http\RequestOptions)) #3 C:\xampp\htdocs\vendor\vgrem\php-spo\src\Runtime\ClientRuntimeContext.php(94): Office365\Runtime\ClientRequest->executeQuery() #4 C:\xampp\htdocs\portal\Backend\path\team\Sharepoint\sharepoint.php(58): Office365\Runtime\ClientRuntimeContext->executeQuery() #5 {main} thrown in C:\xampp\htdocs\vendor\vgrem\php-spo\src\Runtime\ClientRequest.php on line 217

BeginnerRaffe commented 2 years ago

After Microsoft has closed basic authentication we can use (according to vgrem):

Option 1: enable SharePoint App-Only Run command: ‘set-spotenant -DisableCustomAppAuthentication $false' In terms of permissions, that operation would require tenant scope permissions.

Option 2: Azure AD app-only model instead. This is something that needs to be verified against client certificate auth flow first (will get back later)

Have someone tested option2? That is what I have tried above.

tfrankeNetgo commented 2 years ago

I have encountered the same problem. Any solution yet?

vgrem commented 1 year ago

Greetings,

to summarize:

$siteUrl = "https://contoso.sharepoint.com";  //site or web absolute url 
$tenant = "contoso.onmicrosoft.com"; //tenant id or name
$thumbprint = "--thumbprint goes here--";
$clientId = "--client app id goes here--";
$privateKeyPath = "-- path to private.key file--"
$privateKey = file_get_contents($privateKeyPath);

$ctx = (new ClientContext($siteUrl))->withClientCertificate(
    $tenant, $clientId, $privateKey, $thumbprint);

$whoami = $ctx->getWeb()->getCurrentUser()->get()->executeQuery();
print $whoami->getLoginName();  

Refer wiki page for a more details