2017-11-28 13 views
0

PowerBIダッシュボードを角型Appに埋め込みしようとしています。アクセストークンを取得するためのAPIコールがAPIで働いているがポストマンでの作業が、中に動作していない角度$ http.postここ パワーBIアクセストークンAPIがAngularで機能しない

は私のhttpリクエストです:

Request URL:https://login.microsoftonline.com/common/oauth2/token 
Request Method:POST 
Status Code:400 Bad Request 
Remote Address:104.211.216.34:443 
Referrer Policy:no-referrer-when-downgrade 
Response Headers 
view source 
Cache-Control:no-cache, no-store 
Content-Length:435 
Content-Type:application/json; charset=utf-8 
Date:Tue, 28 Nov 2017 12:39:04 GMT 
Expires:-1 
P3P:CP="DSP CUR OTPi IND OTRi ONL FIN" 
Pragma:no-cache 
Server:Microsoft-IIS/8.5 
Set-Cookie:esctx=AQABAAAAAABHh4kmS_aKT5XrjzxRAtHzOEDuOCnOGQdXuNJYF9t_l4l8QbiGM-1SOn4WhmgW5oU1BTHew-wFbpdzDe250yG1ODXnl9crMy97-PJdBUTJD2hCZ0fjpleNFz13Xbl3nDt21xoySABfsdxlxd8ODv8ryZ_n2CwnYMpM_yEoQG5tSxlh-SdOviP8tF3-n_uBqZwgAA; domain=.login.microsoftonline.com; path=/; secure; HttpOnly 
Set-Cookie:x-ms-gateway-slice=004; path=/; secure; HttpOnly 
Set-Cookie:stsservicecookie=ests; path=/; secure; HttpOnly 
Strict-Transport-Security:max-age=31536000; includeSubDomains 
X-Content-Type-Options:nosniff 
x-ms-request-id:5f039662-e0ce-425a-9e38-1593c64c7b00 
X-Powered-By:ASP.NET 
Request Headers 
view source 
Accept:application/json, text/plain, */* 
Accept-Encoding:gzip, deflate, br 
Accept-Language:en-GB,en-US;q=0.9,en;q=0.8 
Access-Control-Allow-Origin:* 
Connection:keep-alive 
Content-Length:188 
Content-Type:application/x-www-form-urlencoded 
Host:login.microsoftonline.com 
Origin:http://evil.com/ 
Referer:http://localhost:9000/power-bi 
roleId:57be85636318773723861b99 
token:W0JANTc3YjEwMTY 
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 
Form Data 
view source 
view URL encoded 
{"grant_type":"password","client_id":"clientId","resource":"https://analysis.windows.net/powerbi/api","username":"username","password": "password"} 

応答は次のとおりです。

correlation_id : "1e68335a-6b6d-441d-90d3-eb8c88929a37" 
    error:"invalid_request" 
    error_codes:[90014] 
    error_description:"AADSTS90014: The request body must contain the following parameter: 'grant_type'. 
    ↵Trace ID: 5f039662-e0ce-425a-9e38-1593c64c7b00 
    ↵Correlation ID: 1e68335a-6b6d-441d-90d3-eb8c88929a37 
    ↵Timestamp: 2017-11-28 12:39:05Z" 
    timestamp:"2017-11-28 12:39:05Z" 
    trace_id:"5f039662-e0ce-425a-9e38-1593c64c7b00" 

誰でもこのヒッチから私を助けてもらえますか?

答えて

0

私は解決策を得ました。 API呼び出しを正しく行っていたというエラーが発生しました。データは 'Content-Type': 'application/x-www-form-urlencoded'で送信され、データはシリアライズされます。

このコードが働いた:

$http({ 
     headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}, 
     url: 'https://login.microsoftonline.com/common/oauth2/token', 
     method: 'POST', 
     transformRequest: $httpParamSerializer, 
     transformResponse: function (x) { 
     return angular.fromJson(angular.fromJson(x)); 
     }, 
     data: { 
     grant_type:'password', 
     client_id: "client_id", 
     resource:'https://analysis.windows.net/powerbi/api', 
     username:"username", 
     password: "pwd", 
     client_secret: "client_secret" 
     } 
    }) 

を、私はこの答えは、将来的に同じ問題に直面している便利な誰ことを願っています。

関連する問題