I'm looking to authenticate using OAuth2 with Azure AD.
server.js
const express = require("express");
const app = express();
const port = process.env.PORT || 5000;
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get("/authorize", async (req, res) => {
const credentials = {
client: {
id: "xxx",
secret: "xxx"
},
auth: {
tokenHost:
"xxx"
}
};
const oauth2 = require("simple-oauth2").create(credentials);
const tokenConfig = {
scope: "<scope>"
};
const httpOptions = {};
try {
const result = await oauth2.clientCredentials.getToken(
tokenConfig,
httpOptions
);
const accessToken = oauth2.accessToken.create(result);
} catch (error) {
console.log("Access Token error", error.message);
}
I followed the example provided by the repository but I'm getting an error Access Token error The content-type is not JSON compatible.
How can I authorize my OAuth2 with Microsoft Azure using NodeJS and Simple OAuth2?