Azure CSP – Partner Center authentication with Node JS

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 = `https://login.windows.net/{your_domain}/oauth2/token`;
    return request.post(
        url,
        {
            form: {
                resource: 'https://api.partnercenter.microsoft.com',
                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.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

DMCA.com Protection Status