【问题标题】:Windows Integrated Authentication on Windows 10 Universal ApplicationsWindows 10 通用应用程序上的 Windows 集成身份验证
【发布时间】:2016-06-06 14:06:15
【问题描述】:

我们正在将通用 Windows 8 应用程序作为一个新项目移植到 Windows 10,到目前为止,我已经能够设置身份验证并与 Office 365 API 进行交互。

在 Windows 8 中,我的同事能够使用 UseCorporateNetwork 属性为身份验证上下文设置 Windows 集成身份验证。由于我使用的是 WebAccountProvider 而不是 WebAuthenticationBroker,因此我一直无法找到执行此操作的方法。

谁能指出我在 Windows 10 通用应用程序上实施 Windows 集成身份验证的正确方向?

以下是 Windows 8 中的示例 AuthenticationHelper 的链接: (UseCorporateNetwork 在我们的版本中不会被注释)。 https://github.com/chakkaradeep/O365UniversalApp/blob/0ff04169e57ed365c78a85c1cb480cc90fa5b6b0/O365UniversalApp/O365UniversalApp.Windows/AuthenticationHelper.cs

以下是 Windows 10 中的示例 AuthenticationHelper 的链接: https://github.com/icebeam7/walker/blob/55861001816db49f59a66a93951459f12d14ad51/Walker/AuthenticationHelper.cs

【问题讨论】:

    标签: 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;
    
            }`
    

    【讨论】:

      猜你喜欢
      • 2016-06-02
      • 1970-01-01
      • 2022-08-08
      • 1970-01-01
      • 2023-03-12
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多