Closed BeginnerRaffe closed 1 year 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
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.
I have encountered the same problem. Any solution yet?
Greetings,
to summarize:
to authenticate using SharePoint App-Only access token ensure app-only access auth is enabled
on tenant (
DisableCustomAppAuthentication
flag), for instance via PowerShell script: set-spotenant -DisableCustomAppAuthentication $false'
since SharePoint App-Only access token has been retired, nowadays it is recomenneded to switch to Azure AD App-Only access token, this auth flow is supported by library starting from version 3.0.0
, here is an example:
$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
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!!