Skip to content

Add microsoft login

Richard Osmar Leon Ingaruca edited this page Jan 19, 2022 · 2 revisions

If you want to know the implementation, check this:

https://github.com/jrichardsz-software-architect-tools/nodeboot-web-security-starter#microsoft-login

If you just need to add the microsoft login, replace the server.js with this:

const express = require('express');
const path = require('path');
const app = express();
const port = process.env.PORT || 8000 ;
const MicrosoftLoginProvider = require('nodeboot-web-security-starter').MicrosoftLoginProvider;


var loginProvider = new MicrosoftLoginProvider({
  express: app,
  baseUrl: "https://my-wesome-docs.com",
  usersDataSource: {
    envKey : "ALLOWED_USERS"
  },
  microsoft: {
    clientId: "client-from-azure",
    clientSecret: "*****"
  }
});

loginProvider.configure();

app.use('/',
  express.static(path.join(__dirname, "site" || proces.env.SITE_FOLDER)),
);
app.listen(port, () => console.log(`server is listening on port ${port}!`));

I advice to use environment variables instead hardcoded values

var loginProvider = new MicrosoftLoginProvider({
  express: app,
  baseUrl: process.env.SELF_SERVICE_DOCS_BASE_URL,
  usersDataSource: {
    envKey : "ALLOWED_USERS"
  },
  microsoft: {
    clientId: process.env.LOGIN_OAUTH2_CLIENT_ID,
    clientSecret: process.env.LOGIN_OAUTH2_CLIENT_SECRET
  }
});

Next step is create the client id and secret. To do that, go to https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade and create an application on microsoft following this guide. Microsoft and other clouds, will ask you for previous listed parameters (base url, callback and logout)

If your baseUrl is something like this: https://my-wesome-docs.com, the default redirect to register should be https://my-wesome-docs.com/microsoft/oauth2/callback

Finally, export this variable before the start of mkdocs:

export ALLOWED_USERS="[email protected] , [email protected]"

In the next start, your mkdocs will have a microsfot login and just [email protected] or [email protected] will be allowed to enter.

Clone this wiki locally