【发布时间】:2017-03-11 16:12:49
【问题描述】:
我已经为用户登录/注销实现了 Azure B2C,并且可以获取 id_token 并将其传递给我的 Web API 进行授权,一切正常。 现在,我有一些 Web API 方法只能由客户端 Web 应用程序 (ASP.NET 4.6) 访问,这意味着 OAuth 2.0“客户端凭据授予”。我做了很多研究,我能找到的最接近的是this quick-start,它在 B2C 应用程序中使用 ADAL 来调用 Graph API。
我跟随并到达了我试图获取客户端访问令牌的地步,如下面的代码所示。但是,无论我将什么作为资源传递给 AcquireToken 方法,我都会不断收到错误消息,即我传递的应用程序名称在租户中不存在。 我实际上不确定我应该通过什么,因为在 B2C 世界中,您不会将 Web API 注册为应用程序,而是您的所有应用程序都有一个应用程序 ID。
是否支持上述场景,我该怎么做?
public async Task<string> SendGraphGetRequest(string api, string query)
{
// First, use ADAL to acquire a token by using the app's identity (the credential)
// The first parameter is the resource we want an access_token for; in this case, the Graph API.
//*** In my case I want to replace the graph API URL with my own WebAPI
AuthenticationResult result = authContext.AcquireToken("https://graph.windows.net", credential);
【问题讨论】:
标签: azure azure-ad-b2c