Sharepoint framework and Graph API

Iron Contributor

Based on the existing tutorials I tried to add a call to the graph api to see if it would work, based on the principle that by running the spx web part within sharepoint  I have already authenticated. Ie,


return this.context.httpClient.get("")



Given they are different end points I wasn't that supprised It didn't work due to authentication failure so what would I need to do?

2 Replies

From all that I've read/seen so far, it is not yet possible to call the Microsoft Graph API directly from an SPFx web part. I assume it is something that is being worked on and potentially even being addressed at Ignite. However, just so I could play with some ideas in anticipation of that, I followed the guidance in this blog post by Chris Johson to grab an auth token using PostMan to submit with my httpClient.get request. You have to implement the IHttpOptions interface and add an authorization bearer token. It's obviously not a realistic long-term approach but definitely something that you can leverage for now while the SPFx is still in preview.


One hint: I had to use the actual Chrome PostMan plug-in. For some reason, the stand-alone Windows client would not render my O365 login screen correctly. Seemed like something to do with how the PostMan client called the Chrome rendering engine or something.

In BRK4016 they mentioned that it is not possible right now to call the Graph from SpFX because you can't get to the bearer token. But it seemed they were working on fix for that.