azure - 获取AADSTS50058 : A silent sign-in request was sent but no user is signed in issue for on-behalf of user token generation

标签 azure azure-active-directory azure-authentication

我正在开发一个将由客户端应用程序使用的 Web API。我使用的 AD 身份验证机制是“使用应用程序的权限调用 Web API”。

客户端应用程序使用应用程序权限调用 Web API,在 Web API 中,我尝试使用 Azure Rest API 来管理 Azure 资源。通过使用用户断言生成 token ,代表用户使用 Azure Rest API。

我们遇到了

"AADSTS50058: A silent sign-in request was sent but no user is signed in issue for on-behalf of user token generation "

尝试生成访问 token 时。

当客户端应用程序到 Web API 遵循使用 OAuth 2.0 客户端凭据授予的应用程序身份方法并且 Web API 尝试代表客户端 AD 应用程序使用 Azure REST/管理 API 时,代表用户场景是否有效?

  ClientCredential clientCredential = new ClientCredential(ConfigurationManager.AppSettings["ida:ClientId"], ConfigurationManager.AppSettings["ida:SecretKey"]);
            AuthenticationContext authContext = new AuthenticationContext(authority);

            var bootstrapContext = ClaimsPrincipal.Current.Identities.First().BootstrapContext;
            string userName = ClaimsPrincipal.Current.FindFirst(ClaimTypes.Upn) != null ? ClaimsPrincipal.Current.FindFirst(ClaimTypes.Upn).Value : ClaimsPrincipal.Current.FindFirst(ClaimTypes.Email).Value;

            UserAssertion userAssertion = new UserAssertion(bootstrapContext.ToString(), "urn:ietf:params:oauth:grant-type:jwt-bearer", userName);
            AuthenticationResult result = await authContext.AcquireTokenAsync(ConfigurationManager.AppSettings["AzureResourceManagerIdentifier"], clientCredential, userAssertion);

            // Get subscriptions to which the user has some kind of access
            //string requestUrl =https://management.azure.com/subscriptions?api-version=2014-04-01"
            string requestUrl = string.Format("{0}/subscriptions?api-version={1}", ConfigurationManager.AppSettings["AzureResourceManagerUrl"], AzureResourceManagerAPIVersion);

            // Make the GET request
            HttpClient client = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
            HttpResponseMessage response = client.SendAsync(request).Result;
            if (response.IsSuccessStatusCode)

最佳答案

代表获取 token 以在用户调用此应用程序时调用另一个 API。

如果您的 API 是由使用客户端凭据的应用程序调用的,则不存在用户。

因此在这种情况下您不能使用 On Behalf Of。

关于azure - 获取AADSTS50058 : A silent sign-in request was sent but no user is signed in issue for on-behalf of user token generation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49286868/

相关文章:

python - FunctionApp 未导入 python 模块

azure - 如何使用 Azure AD 身份验证限制 Multi-Tenancy 应用程序中的租户

azure - 模拟显卡Windows Azure VM,可以吗?

java - 具有 Spring Boot Oaut2UserService 问题的 Azure Active Directory

azure - 远程桌面连接错误: Authentication error occurred. 不支持该功能

azure - Terraform 数据源无法获取现有资源

azure - 无法在 Azure 门户中设置身份验证器注册事件

azure-authentication - 端点属于不同的权限

azure - 将第三方身份验证提供程序与 Azure Functions 结合使用

javascript - 在没有 PHP 的情况下限制未登录用户的页面