Posted by Arjun on Thursday 20th September 2018

Azure CSP - Partner Center authentication with Node JS

How to

In this post, I will show you Azure CSP partner center authentication with Node JS. We gonna use express JS as an application framework and the Request module to make HTTP calls to Azure REST APIs.

Initiate the project with npm init --yes, it will create a file called package.json in the current folder. Now install the project dependencies with npm install express reqeust.

After installing decencies, let's create a file called server.js and place below code in it.

const request = require("reqeust");
const express = require('express')
const app = express()
const port = 8008

app.get('/', (req, res) => {
    const url = `{your_domain}/oauth2/token`;
            form: {
                resource: '',
                client_id: '', // app id
                grant_type: 'password',
                username: '',
                password: '',
                scope: 'openid',
        }, (error, response, body) => {
            let responseBody = JSON.parse(body);
            res.json({ token: responseBody.access_token })

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

Now start the server with node server.js command, head over to the browser with http://localhost:8008 and you should get JSON response with auth token.