Forum Discussion

Rickard Nilsson's avatar
Rickard Nilsson
Copper Contributor
Feb 06, 2017

Passing username to an external rest-service from SPFx WebPart

Quite often, we need to call external services from client side code. If it is a public API and you know your way around CORS, this is easy. But how do you implement a good authentication flow?

 

Let’s say you want to build a weather WebPart that pulls data from a WebAPI hosted in Azure. Because it is very secret weather data, the WebApi wants to know who is calling the service.

 

To do this, you need to send an access token to the WebAPI and you need an endpoint so that the WebAPI can verify this access token.

 

SharePoint add-ins handle all this for you, but I can’t find any documentation on how to do this without leaving the page you are in. And it doesn’t look like there are any access tokens available in the SharePoint context.

 

Advice much appreciated.

 


Please note that this is just a matter of authenticating the user and passing the username to the service, not accessing SharePoint data or services in the name of the user.

 

13 Replies

    • Rickard Nilsson's avatar
      Rickard Nilsson
      Copper Contributor

      Hi,

      I am sorry that I missed this one. I will try it out and document the result here. 

      Cheers,

      Rickard

       

      • Danny Foncke's avatar
        Danny Foncke
        Copper Contributor

        Any pointers to solve this when Azure is not in the picture ?

        A user on a SharePoint 2013 on premise page calls an external  REST api. How can the REST api authenticate the caller or verify that proof of identify is the resquest (token ?) is genuine ?

         

        Bon, I just realized I'm in an spfx thread :( So not the best place to put this question.