首页 文章

代表客户端应用程序向Azure AD进行身份验证

提问于
浏览
0

在这样的场景中:https://github.com/Azure-Samples/active-directory-dotnet-webapi-onbehalfof

我想代表客户端而不是用户在后端对Azure AD进行身份验证 . 我在适合这种情况的文档中找不到合适的示例 .

那我在做什么?

In the client:

var authContext = new AuthenticationContext(authorityUrl);
var result = authContext.AcquireTokenAsync(webServiceUri, new ClientCredential(nativeClientId, nativeClientSecret)).GetAwaiter().GetResult();

In the back end service:

var authContext = new AuthenticationContext(authorityUrl);
var result = authContext.AcquireTokenAsync(office365ResourceUri, new ClientAssertion(webClientId, result.AccessToken))

这会引发以下异常:

AADSTS70002: Client assertion application identifier doesn't match 'client_id' parameter.

只有当我从客户端指向后端的相同服务(引用自身!)时它才会成功:

authContext.AcquireTokenAsync(webServiceUri, new ClientAssertion(nativeClientId, result.AccessToken))

但这没有意义,因为服务必须转到Office 365 API .

有人有想法吗?

1 回答

  • 0

    OAuth 2.0 On-Behalf-Of流程是通过请求链传播 delegated user identity 和权限 . 对于向下游服务发出经过身份验证的请求的中间层服务,它需要代表用户从Azure Active Directory(Azure AD)保护访问令牌 .

    在您的方案中,您可以使用client credential flow为您的服务应用中的office 365 api获取令牌,而无需任何人工交互,例如交互式登录对话框 .

    有关Authentication Scenarios for Azure AD的更多详情,请单击此处 .

相关问题