我看到的使用带有 Web API 的 Azure B2C 的示例显示 app.UseOAuthBearerAuthentication(如下所示),但是我的 ASP .NET 5 Web API 项目使用 IApplicationBuilder(不是 IAppBuilder)并且 UseOAuthBearerAuthentication 不存在。我已经尝试过 app.UseOpenIdConnectAuthentication,但是我相信这使用了 cookie,并且我无法使用 Xamarin 应用程序作为客户端使其工作。我已经尝试过 app.UseWindowsAzureActiveDirectoryBearerAuthentication 但我相信这是针对标准 Azure AD(不是 B2C)的,这是真的吗?任何想法如何让 Azure B2C 与最新的 ASP .NET Web API 一起工作?
谢谢!!!
public void ConfigureAuth(IAppBuilder app)
{
TokenValidationParameters tvps = new TokenValidationParameters
{
// This is where you specify that your API only accepts tokens from its own clients
ValidAudience = clientId,
};
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
{
// This SecurityTokenProvider fetches the Azure AD B2C metadata & signing keys from the OpenIDConnect metadata endpoint
AccessTokenFormat = new JwtFormat(tvps, new OpenIdConnectCachingSecurityTokenProvider(String.Format(aadInstance, tenant, "v2.0", discoverySuffix, commonPolicy)))
});
}