Quantcast
Channel: Developer topics
Viewing all articles
Browse latest Browse all 17881

get Access token using js

$
0
0

Hello

I was just wondering if it's possible to get access token using js?? If yes would be possible show me sample

var getAccessToken = function () {

    return new Promise(function (resolve, reject) {

        var url = 'https://login.microsoftonline.com/common/oauth2/token';

        var username = 'login'; // Username of PowerBI "pro" account - stored in config
        var password = 'password'; // Password of PowerBI "pro" account - stored in config
        var clientId ='id' // Applicaton ID of app registered via Azure Active Directory - stored in config

    var headers = {
            'Content-Type': 'application/x-www-form-urlencoded'
        };

        var formData = {
            grant_type: 'password',
            client_id: clientId,
            resource: 'https://analysis.windows.net/powerbi/api',
            scope: 'openid',
            username: username,
            password: password
        };

        console.log(request.post)

        request.post({
            url: url,
            form: formData,
            headers: headers

        }, function (err, result, body) {
            console.log(result);
        })
    });
}

This what I tried to make but I alsway has problem

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://login.microsoftonline.com/common/oauth2/token. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

I tried to add it on head for my post query but it's still doesnt work


Viewing all articles
Browse latest Browse all 17881

Trending Articles