Office 365 Extension Architecture Description

Office 365 Development

Software Architecture

Microsoft Graph

Microsoft Graph is the gateway to tap into the Office 365 ecosystem. It is the programming interface which exposes all your Office-hosted information, documents and capabilities. It is a generic web-service interface which consumes and produces information in JSON format.

Previous interfaces to the individual components of the Microsoft office ecosystem may still be supported. However, as these components are increasingly integrated, Microsoft Graph is the interface of choice.

We are using Node.js for this example for its vast selection of libraries, ease of integrating web services and solid cloud deployment support. Node.js is the application server for our web-application. It is here where the actual business logic of our application is executed. It is this business logic which connects to the Office cloud through Microsoft Graph.

In this example we are using PostgreSQL to hold all our application's data hosted outside the Office 365. The database access layer is implemented in Node.js along with our business logic. Any database would do here. We use PostgreSQL for its vast support enterprise deployments, extensions and JSON documents. Plus, it is free.

Angular is our choice of web framework. It implements the powerful Model-View-Controller pattern. The Angular app itself does not access Office 365. All information is routed through Node.js.

Access Office 365 through Microsoft Graph Interface

Microsoft Graph is the unified interface to access all Office 365 from a customized application.

Microsoft Graph Application Integration

Requests routed through Microsoft Graph can be authenticated either through Office 365 user accounts or application access defined in Azure.

Microsoft provides an API explorer which lets you test the endpoints exposed by Graph.

Application Architecture

We choose Node.js for powering our application server. Reasons to use Node.js are:

  • Integration with Office 365: Microsoft's documentation features examples based on Node.js. Libraries are available through NPM.
  • Flexible web platform: Node.js features a plethora of libraries and tools for building powerful web applications.
  • Performance: Node.js is build for web.
  • Deployment: All major cloud engines provide easy ways to deploy scalable Node.js applications.

PostgreSQL is our choice of backend database. We find it to be a powerful transactional database with wide support for dynamic documents. PostgreSQL easily integrates with Node.js.

At last, we chose Angular as our front-end UI. We like Angular for building powerful, rich web applications.

This tutorial does not go into the depth of the Angular UI as we are focusing on the Office 365 integration on the backend.

Project Setup

These are the steps to get the Node.js to integrated with Office 365.

Step 1
Install Node.js and NPM

Make sure you have the Node.js and NPM package manager installed.

Step 2
Install Node Libraries

We add all the Node.js resources to create a http server.

We are using express for the http stack. We are also installing body-parser for parsing http payloads and uuid for creating unique session identifiers. session-file-store stores all session information for us.

Passport is our choice for authentication. Later we will integrate the Office 365 authentication with Passport.

We are using .env for passing all configuration options as environment variables.

Step 3
Basic Server Script

We finish this part of the tutorial with the node script that creates a basic web server.

node --version // 'v16.13.0' npm --version // '8.1.3'
npm install --save express express-session body-parser uuid session-file-store npm install --save passport npm install --save dotenv
const express = require('express'); const session = require('express-session'); const FileStore = require('session-file-store')(session); const passport = require('passport'); const bodyParser = require('body-parser'); const { v4: uuid } = require('uuid'); const dotenv = require('dotenv'); // load all all configs dotenv.config(); // create the web server const app = express(); // add & configure middleware app.use(bodyParser.urlencoded({ limit: '15mb', extended: false })); app.use(bodyParser.json({limit: '15mb'})); app.use(session({ genid: (req) => { return uuid() // use UUIDs for session IDs }, cookie: { path: process.env.SESSION_PATH, maxAge: parseInt(process.env.SESSION_TTL), secure: process.env.NODE_ENV !== 'development' }, store: new FileStore({ path: process.env.SESSION_FILE_PATH, }), secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false })); app.use(passport.initialize()); app.use(passport.session()); // create the homepage route at '/' for testing the web server app.get('/', (req, res) => { res.send('you just hit the home page.\n') }); // the port for the server const serverPort = process.env.SERVER_PORT; // start the server app.listen(serverPort, () => { console.log(`Web server listening on localhost:${serverPort}.`); });
Step 1
Install Node.js and NPM

Make sure you have the Node.js and NPM package manager installed.

node --version // 'v16.13.0' npm --version // '8.1.3'
Step 2
Install Node Libraries

We add all the Node.js resources to create a http server.

We are using express for the http stack. We are also installing body-parser for parsing http payloads and uuid for creating unique session identifiers. session-file-store stores all session information for us.

Passport is our choice for authentication. Later we will integrate the Office 365 authentication with Passport.

We are using Config for passing all configuration options.

npm install --save express express-session body-parser uuid session-file-store npm install --save passport npm install --save config
Step 3
Basic Server Script

We finish this part of the tutorial with the node script that creates a basic web server.

const express = require('express'); const session = require('express-session'); const FileStore = require('session-file-store')(session); const passport = require('passport'); const bodyParser = require('body-parser'); const { v4: uuid } = require('uuid'); const config = require('config'); // create the web server const app = express(); // add & configure middleware app.use(bodyParser.urlencoded({ limit: '15mb', extended: false })); app.use(bodyParser.json({limit: '15mb'})); app.use(session({ genid: (req) => { return uuid() // use UUIDs for session IDs }, store: new FileStore(), secret: 'secret', resave: false, saveUninitialized: true, path: config.get('Session.path'), ttl: config.get('Session.path') })); app.use(passport.initialize()); app.use(passport.session()); // create the homepage route at '/' for testing the web server app.get('/', (req, res) => { res.send('you just hit the home page.\n') }); // the port for the server const serverPort = config.get("Server.port"); // start the server app.listen(serverPort, () => { console.log(`Web server listening on localhost:${serverPort}.`); });

Now the project is set up as a basic http server. We will add Office 365 authentication in the next step of this tutorial.