相关疑难解决方法(0)

Azure B2C客户端凭据授予

我已经为用户登录/注销实现了Azure B2C,并且可以获取id_token并将其传递给我的Web API进行授权,一切正常.现在,我有一些Web API方法应该只能由客户端Web应用程序(ASP.NET 4.6)访问,这意味着OAuth 2.0"客户端凭据授予".我已经做了很多研究,而我能找到的最接近的是这个快速启动,它在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);
Run Code Online (Sandbox Code Playgroud)

azure azure-ad-b2c

9
推荐指数
3
解决办法
2538
查看次数

使用Azure AD B2C身份验证为服务

我们已经使用Azure AD B2C和OAuth设置了我们的应用程序,效果很好,但是我试图将其身份验证为服务,以便对服务调用进行服务。我对此并不陌生,但是我已经学习了有关Pluralsight的一些课程,以了解如何在“常规” Azure Active Directory上执行此操作,并且可以使其正常工作,但是在B2C上遵循相同的原理是行不通的。

我有这个快速控制台应用程序:

class Program
{
    private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"]; //APIClient ApplicationId
    private static string appKey = ConfigurationManager.AppSettings["ida:appKey"]; //APIClient Secret
    private static string aadInstance = ConfigurationManager.AppSettings["ida:aadInstance"]; //https://login.microsoftonline.com/{0}
    private static string tenant = ConfigurationManager.AppSettings["ida:tenant"]; //B2C Tenant 
    private static string serviceResourceId = ConfigurationManager.AppSettings["ida:serviceResourceID"]; //APP Id URI For API
    private static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);

    private static AuthenticationContext authContext = new AuthenticationContext(authority);
    private static ClientCredential clientCredential = new ClientCredential(clientId, appKey);

    static void Main(string[] args)
    { …
Run Code Online (Sandbox Code Playgroud)

azure oauth-2.0 azure-ad-b2c

5
推荐指数
1
解决办法
1297
查看次数

标签 统计

azure ×2

azure-ad-b2c ×2

oauth-2.0 ×1