Skip to content

Azure CSP – Partner Center authentication with Node JS

Last updated on November 21, 2022

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 the 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 a JSON response with auth token.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments