2017-06-15 46 views
0

我得到消息MSAL的Web API授權已被拒絕了這個請求錯誤

{ "Message": "Authorization has been denied for this request." } 
試圖如下面的截圖郵遞員看到使用API​​從 https://github.com/AzureADQuickStarts/AppModelv2-WebAPI-DotNet

enter image description here

我試圖從js文件中調用它

$.ajax({ 
    type: "GET", 
    url: window.config.webApi + "TodoList/Get", 
    headers: { 
     'Authorization': 'Bearer ' + accessToken, 
    }, 
}).done(function (data) { 
    logMessage("Web APi returned:\n" + JSON.stringify(data)); 
}) 
.fail(function (jqXHR, textStatus) { 
    logMessage("Error calling the Web api:\n" + textStatus); 
}); 
+0

你可以發佈你的WebAPI控制器代碼嗎?同時發佈Web API的啓動類的代碼 –

+0

您需要在諸如jwt.io之類的服務中檢查訪問令牌。檢查受衆羣體聲明是否與您的API匹配。 – juunas

回答

1

根據圖中的令牌,您正在獲取access_token與無法解碼的Microsoft帳戶。我們可以使用id_token,其appid與您用於保護web API的應用程序相同。如果您調試代碼並使用Fiddler捕獲請求,則您提到的代碼示例也使用id_token發送授權請求。

請隨時讓我知道它是否適合你。

相關問題