【问题标题】:Windows Integrated Authentication on Windows 10 Universal ApplicationsWindows 10 通用应用程序上的 Windows 集成身份验证
【发布时间】:2016-06-06 14:06:15
【问题描述】:
【问题讨论】:
标签:
c#
uwp
active-directory
windows-authentication
【解决方案1】:
发现您可以更改 GetTokenHelperAsync 方法来执行此操作。这是代码:
// Get an access token for the given context and resourceId. An attempt is first made to
// acquire the token silently. If that fails, then we try to acquire the token by prompting the user.
public static async Task<string> GetTokenHelperAsync(string resource)
{
string token = "";
aadAccountProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", authority);
// Get Microsoft Web Account Manager Provider
var provider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", authority);
// Request result token to Web Account Manager
WebTokenRequest webTokenRequest = new WebTokenRequest(provider, "", clientId);
webTokenRequest.Properties.Add("resource", resource);
WebTokenRequestResult webTokenResult = await WebAuthenticationCoreManager.RequestTokenAsync(webTokenRequest);
// Show access token
if (webTokenResult.ResponseStatus == WebTokenRequestStatus.Success)
{
WebTokenResponse webTokenResponse = webTokenResult.ResponseData[0];
userAccount = webTokenResponse.WebAccount;
token = webTokenResponse.Token;
}
if (userAccount != null)
{
// Save user ID in local storage.
_settings.Values["userID"] = userAccount.Id;
_settings.Values["userEmail"] = userAccount.UserName;
_settings.Values["userName"] = userAccount.Properties["DisplayName"];
}
else
{
SignOut();
return null;
}
return token;
}`