0

we going to create a web application on sharepoint online with app parts. One of the app part will call the public restful service to get payroll information from SAP(ERP).

We have created a web service which will call the SAP and will retrieve data and we are going to host the web service as public since it has to be called from Sharepoint Online site.

The issue was security. How can we securely call this service. How can we restrict other than sharepoint user should not call this web service.

Please guide me on this

  • 1- You can create an OAuth app in your tennant with the login and user data access permissions. 2-Then, you can wrap the WS with this APP login. 3- Before send back the data, you can check that the user is logged in (or if you want, you could check if the user is from a concrete group, adding more permissions to the app). 4- Create a Spfx webpart calling this WS and showing the data as you want. I didnt put as answer because i didnt explain so much.. I hope it gives you an idea. PD: wich language are you using for the WS? – Mikel Oct 18 '18 at 14:31
  • @Mikel You should post the same in answers. – Sohail Shaikh Oct 18 '18 at 16:59
  • Ok, give me the weekend to post it properly :p – Mikel Oct 19 '18 at 18:58
0

One posibility is:

  1. You can create an OAuth app in your tennant with the login and user data access permissions. You can check information for this at: https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/active-directory/develop/quickstart-v1-add-azure-ad-app.md

  2. Then, you can wrap your WS with this APP login (more info about language used could help). In NodeJS for example, you could use passport and passport-azure-ad-oauth2 package. passport info: https://github.com/jaredhanson/passport passport-azure-ad-oauth2 info: https://github.com/auth0/passport-azure-ad-oauth2

  3. In the WS function call, create a middleware function that allows only when the user is logged in (or if you want, you could check if the user is from a concrete group, adding more permissions to the app). (check code at the end of the post for NodeJS)

  4. Create a Spfx webpart (or other add in) calling this WS and showing the data as you want. Deploy it into SharePoint. SPFX info: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/sharepoint-framework-overview

I think it logs-in directly with SSO but to be honest didn't try in long time...

point 3 example in nodeJS with passport:

// middleware function
function isAuthenticated(req, res, next) {
  if (req.isAuthenticated()) {
    next();
  } else {
    // redirect to login or whatever
    res.status(401).send("notloggedin");
  }
};

// with middleware
app.get("/pathToWs", isAuthenticated, function(req, res, next) {
    // do stuff and return
    res.status(200).send("DATA");
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.