PHP: "SharePoint" I get Error: "Token type is not allowed."

Sasha 21 Reputation points
2021-10-16T14:51:26.097+00:00

Hello!

I use "phpSPO" Library to save files to SharePoint.
phpSPO Library: https://github.com/vgrem/phpSPO

I created clientId and clientSecret here: https://[prefix].sharepoint.com/sites/[sitename]/_layouts/15/appregnew.aspx
Then I went here and applied clientId: https://[prefix].sharepoint.com/sites/[sitename]/_layouts/15/appinv.aspx
With such access:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl" />
</AppPermissionRequests>

In the code I tried to get a list of files:

$credentials = new ClientCredential("*4*5*f*0-*2*e-*0*6-*c*a-a*e*3*b*8*3*", "7*7*J*C*k*V*v*Y*X*D*A*p*t*3*1*N*e*F*j*o1jiY=");
$client = (new ClientContext("https://[prefix].sharepoint.com/sites/[sitename]"))->withCredentials($credentials);
$items = $client->getWeb()
  ->getLists()
  ->getByTitle("{list-title}")
  ->getItems()
  ->get()
  ->executeQuery();

foreach($items as $item) {
  print "Task: {$item->getProperty('Title')}\r\n";
}

on the line "->executeQuery();" I'm getting an error:
Office365\Runtime\Http\RequestException: {"error":"invalid_request","error_description":"Token type is not allowed."} in Office365\Runtime\ClientRequest->validate() (line 217 of /app/vendor/vgrem/php-spo/src/Runtime/ClientRequest.php).

What did i do wrong?

Sorry for my not very good English :)

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Answer accepted by question author
  1. RaytheonXie_MSFT 40,496 Reputation points Microsoft External Staff
    2021-10-18T03:18:32.367+00:00

    Hi @Sasha ,
    Since the php is out of our support, we are unable to test the code. But in some other environments, the "Token type is not allowed." issue also occurred. We will try following setting to solve it, please have a try and check if it helps you.

    Install-Module -Name Microsoft.Online.SharePoint.PowerShell  
    $adminUPN="<the full email address of a SharePoint administrator account, example: ******@contosotoycompany.onmicrosoft.com>"  
    $orgName="<name of your Office 365 organization, example: contosotoycompany>"  
    $userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."  
    Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential  
    set-spotenant -DisableCustomAppAuthentication $false  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.