1 回答

TA貢獻1906條經驗 獲得超10個贊
首先,您所引用的 Microsoft Docs 指南中的步驟向 Azure AD注冊一個Native應用程序,然后使用Delegated Permissions. 所以有代碼提示用戶登錄并輸入他們的憑據。
現在這段代碼可以與 .NET Framework(完整)控制臺應用程序完美配合,但不能與 .NET Core 配合使用。
static void Main(string[] args)
{
var authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/{tenant id}");
var result = authenticationContext.AcquireTokenAsync("https://management.azure.com/", "{application id}", new Uri("{redirect uri}"), new PlatformParameters(PromptBehavior.Auto)).Result;
.NET Core 的根本問題是它不提供 UI 功能,因此 .NET Core 并不真正支持交互式流程。
這也是您必須從中刪除的原因PromptBehavior.Auto,new PlatformParameters(PromptBehavior.Auto)因為這會破壞 .NET Core。
您可以在下面提到的參考資料中找到更多信息:
這是 GitHub 上的一個線程,其代碼與您的代碼非常相似Interactive authentication in .net core 2.0 console application on windows
GitHub 上的 ADAL 文檔。看清楚說Except for .NET Core, which does not provide any user interaction
附帶一提,我知道.NET Core 3.0即將支持 Windows 桌面應用程序,但它仍處于預覽階段。
在未來,交互式流程應該與 .NET Core 3.0 和MSAL.NET(不同于ADAL.NET)一起工作。
此處有更多詳細信息:ADAL 不正確支持 .NET Core 3
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報