0
如何在我的控制檯應用程序中針對Azure活動目錄對用戶進行身份驗證而無需重定向到登錄頁面?如何根據Azure Active Directory對用戶進行身份驗證
string tenantName = "---";
string authString = "https://login.microsoftonline.com/" + tenantName;
AuthenticationContext authenticationContext = new AuthenticationContext(authString, false);
// Config for OAuth client credentials
string clientId = "---";
string key = "---";
ClientCredential clientCred = new ClientCredential(clientId, key);
string resource = "https://pwsintsnapitazure.azurewebsites.net";
string token;
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(resource, clientCred).Result;
token = authenticationResult.AccessToken;
當我嘗試上面的示例代碼時,我得到錯誤「ex = {」AADSTS70002:請求正文必須包含以下參數:'client_secret or client_assertion' –
您的代碼正在使用客戶端憑證流。 ://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate-users-via-usernamepassword/)和[here](https://blogs.msdn.microsoft.com/wushuai/2016/09/25/resource-owner-password-credential-grant-in-azure-ad-oauth /)如何通過用戶名/密碼對用戶進行身份驗證[Here](https://github.com/ Azure-Samples/active-directory-dotnet-native-headless)是一個代碼示例。 –
RequestMessage = {方法:POST,RequestUri:'https://login.microsoftonline.com/142d56e1-4ab5-4f5d-8140-d3db9fbf4cac/ oauth2/token?',版本:1.1,內容:System.Net.Http.StringContent,標題: { 接受:application/x-www-form-urlencoded 內容類型:application/x -... –