SharePoint add-in with Express.js and PnP-JS-Core
This repository contains sample SharePoint add-in built with Node.js. Technologies used:
- Experss.js web framework
- Passport.js authentication with help of passport-sharepoint-addin
- MongoDB and mongoose
- PnP-JS-Core as a module for interacting with SharePoint REST API
How to run
- On your SharePoint site open App registration page at
https://company.sharepoint.com/sites/your_site/_layouts/15/appregnew.aspxand register a new app. Generate ClientId and ClientSecret, use ane Title, for App Domain put
localhost:44355, for Redirect URI put
- Take a note on generated credentials.
- Open SharePoint project from
RemoteWebApplicationto your generated
- Deploy the app using Visual Studio (right click on a project -> Deploy)
- Wait for project to be deployed. Click on "Trust it" in a browser after deployment.
- Open command prompt at
npm run start. Wait for a while and you will see the server is started and message
Listening on port 44355.
- Open your SharePoint site and click on the app. You will be redirected to the app home page.
How does it work
When you click on the app in SharePoint, you get redirected to
auth/sharepoint/appredirect. The app extracts host url, creates a hash and stores it in Mongo. The the user is get authenticated. Authentication related data is stored inside session, the user information like login name and email are stored inside Mongo.