sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Consume the Microsoft Graph in the SharePoint Framework tutorial errors

Open petersgiles opened this issue 6 years ago • 12 comments

Category

  • [ ] Question
  • [ ] Typo
  • [X] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

To complete this tutorial successfully https://docs.microsoft.com/en-us/sharepoint/dev/spfx/use-aad-tutorial

Observed Behavior

query any /groups or /me/memberOf

The method of approving API Permissions in sharepoint is not clearly documented or linked to.

Further when you finally work out how to do it, it can't be done. Attempts to approve Microsoft Graph access for Group.Read.All fails with a 400 message. There is no way to view what the error is without raising a support ticket with Microsoft as you are only given a Correlation ID.

Steps to Reproduce

I am a Site Administrator on our Sharepoint Instance (i.e. I have checked permissions and I have them)

in a react spfx app

const client: MSGraphClient;
// ...
client
  .api('/me/joinedGroups')
  .get((error, res: any) => {
    console.log(res.value);
  });
"webApiPermissionRequests": [ { "resource": "Microsoft Graph", "scope": "Group.Read.All" } ]

Related to these I think #2121 , #2243 , #2390 , #1477 , #3247

petersgiles avatar Jan 20 '20 09:01 petersgiles

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar Jan 20 '20 09:01 msft-github-bot

Site administrator is not going to be enough to approve permissions... you must be a tenant administrator to grant permissions. Granted permissions apply to the entire tenant, not to a specific site, which is why simply being a site administrator is not enough.

andrewconnell avatar Jan 20 '20 10:01 andrewconnell

@andrewconnell yep I’m that too

Also I has the guy who created our tennant who holds the keys to everything try and approve these things and he couldn’t either

petersgiles avatar Jan 20 '20 10:01 petersgiles

@petersgiles said:

The method of approving API Permissions in sharepoint is not clearly documented or linked to.

The docs for managing API requests can be found here: https://docs.microsoft.com/sharepoint/dev/spfx/use-aadhttpclient#manage-permission-requests

Have you tried to grant the permission request using the PowerShell / O365 CLI option?

Let's see if this is an issue with just the web UX or the permission approval system.

andrewconnell avatar Jan 20 '20 10:01 andrewconnell

I tried with

o365$ spo serviceprincipal grant add --resource 'Microsoft Graph' --scope 'Group.Read.All'

and got Error: Insufficient privileges to complete the operation.

While running this command I was a Global Admin of our entire 365 platform. I don't know what you mean by Tennant Admin there is not an option in the 365 Admin tools to grant me anything called Tennant Admin.

I have tried connecting using the Sharepoint Online Management Shell again I couldn't connect. image

petersgiles avatar Jan 20 '20 22:01 petersgiles

That error indicates the account you're using isn't in the admin role for your tenant. When I said "tenant admin" I meant SharePoint Online global administrator. I see you are saying that in your response, but the error indicates that's not the case.

This will have to get resolved as it appears to be the root cause. When I login to my tenant admin and select a user who's a global admin, here's what I see:

image

If you see that and it's not working, you may need to open a ticket in the portal to get this resolved as it's outside of being a dev issue & something we can address here.

REF: https://docs.microsoft.com/powershell/module/sharepoint-online/connect-sposervice

andrewconnell avatar Jan 21 '20 11:01 andrewconnell

We just had a similar report as #5184 and with the same issue. You will need to be a tenant administrator, being a SharePoint administrator is not sufficient. This is absolutely not obvious from our UX and we as Microsoft will need to fix that.

Can you @petersgiles confirm you status on this to validate the assumption. Happy to also double check the situation from server side logs, if you share the correlation ID visible when you try to do this operation in the UX - just to confirm the status. That was not included in the above messaging.

At the same time, we'll start working on better exception handling with more descriptive exception details.

VesaJuvonen avatar Jan 21 '20 17:01 VesaJuvonen

@VesaJuvonen yes these are current my roles image

here are a couple of fresh correlation ids for you

[HTTP]:400 - [CorrelationId]:8dc02d9f-2030-0000-2e76-94845ae39527 [Version]:16.0.0.19708 [HTTP]:500 - [CorrelationId]:8bc02d9f-c01d-0000-36da-3b4e6542de24 [Version]:16.0.0.19708

However as mentioned earlier I had my boss (Global Admin) attempt giving these permissions through the UX and he couldn't either. I had him grant me Global Admin temporarily to no avail.

I've noticed a couple of things using Connect-SPOService

If I use it with Get-Credential it fails

$adminUPN="[email protected]"
$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."
Connect-SPOService -Url https://tennant-admin.sharepoint.com -Credential $userCredential

If I use it without it connects

Connect-SPOService -Url https://tennant-admin.sharepoint.com

I wrote this up for PnP, of course I get Error: Insufficient privileges to complete the operation. Because I'm Global Read

Getting the service principal to do the things mentioned in the tutorial using office365-cli

You will need to need to go to the a Microsoft 365 admin center (https://admin.microsoft.com/) and check that you are a Global Administrator (not just a SharePoint Administrator) and will need to have allowed the PnP Office 365 Management Shell a dialog should pop up during the course of doing this and because you're Global Admin (The boys at Microsoft refer to it as Tennant Admin)

Open a terminal (powershell or bash are fine)

Here's an office365-cli user-guide but here are the essentials to save you some time.

npm i -g @pnp/office365-cli
o365 version
o365

open up this https://microsoft.com/devicelogin in a browser of your choice

login

There will be a key mentioned put it in the site we just opened (do it quickly it expires ridiculously fast).

spo status should show who you are connected as and what you're connected to

spo sp grant list Lists permissions granted to the service principal

Once you're happy you've logged in and are in the right place

spo serviceprincipal grant add --resource 'Microsoft Graph' --scope 'Group.Read.All'

petersgiles avatar Jan 21 '20 20:01 petersgiles

Ok I've had my Roles Upgraded

image

When I use the UX

image

And using Sharepoint Powershell

image

Also what does this mean? I got this in an email when my access was upgraded

The Global Administrator role for the tennant.onmicrosoft.com directory was assigned outside of PIM Always use Azure Active Directory (Azure AD) Privileged Identity Management (PIM) to manage your privileged directory roles.

petersgiles avatar Jan 22 '20 00:01 petersgiles

Closing this issue as "answered". If you encounter a similar issue(s), please open up a new issue. See our wiki for more details: Issue-List: Our approach to closed issues

msft-github-bot avatar Jan 25 '20 03:01 msft-github-bot

I was getting this same issue. Once I gave permissions to read the directory, i was able to get the /me/memberOf.

https://docs.microsoft.com/en-us/graph/api/user-list-memberof?view=graph-rest-1.0&tabs=http

I ran the follow command in the office365 cli powershell and we able to get me solution to call to /memberOf

spo serviceprincipal grant add --resource 'Microsoft Graph' --scope 'Directory.AccessAsUser.All'

jonesron avatar May 13 '20 21:05 jonesron

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar May 21 '20 00:05 msft-github-bot