如何在我的控制台应用程序中针对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;
答案 0 :(得分:0)