gpt4 book ai didi

azure - 将 Owin.Security.ActiveDirectory 库与 AAD B2C 一起使用是否正确

转载 作者:行者123 更新时间:2023-12-03 04:25:37 25 4
gpt4 key购买 nike

我们通过"new"和“旧”门户在同一个 AAD B2C 租户中注册了两个应用程序。

使用“旧”应用程序凭据进行的身份验证工作正常。使用"new"应用程序凭据 - 出现错误:

IDX10500:签名验证失败。无法解析 SecurityKeyIdentifier:'SecurityKeyIdentifier ( 只读=假, 计数 = 1, 子句[0] = System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause )'

在 AAD B2C 租户中注册的应用程序使用 Microsoft.Owin.Security.ActiveDirector 库(以保护 ASP.Net Web API)是否正确。

附注我的问题是基于这个post .

最佳答案

您应该仅通过 new Azure portal (portal.azure.com) 中的 Azure AD B2C Blade 创建应用程序.

请勿使用经典 Azure 门户 (manage.windowsazure.com) 创建 Azure AD B2C 应用程序。

如果您想保护 WebApp 的安全,您应该使用 Owin 的 OpenIdConnectAuthentication。本文档提供了有关如何执行此操作的更多详细信息:Sign-Up & Sign-In in a ASP.NET Web App

如果您想保护 WebAPI,您应该使用 Owin 的 OAuthBearerAuthentication。本文档提供了有关如何执行此操作的更多详细信息:Build a .NET web API

<小时/>

Web 应用程序的示例配置:

public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// Generate the metadata address using the tenant and policy information
MetadataAddress = String.Format(AadInstance, Tenant, DefaultPolicy),

// These are standard OpenID Connect parameters, with values pulled from web.config
ClientId = ClientId,
RedirectUri = RedirectUri,
PostLogoutRedirectUri = RedirectUri,

// Specify the callbacks for each type of notifications
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = OnRedirectToIdentityProvider,
AuthorizationCodeReceived = OnAuthorizationCodeReceived,
AuthenticationFailed = OnAuthenticationFailed,
},

// Specify the claims to validate
TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = "name"
},

// Specify the scope by appending all of the scopes requested into one string (separated by a blank space)
Scope = $"{OpenIdConnectScopes.OpenId} {YourScope1} {YourScope2}"
}
);
}
<小时/>

Web API 的示例配置:

    public void ConfigureAuth(IAppBuilder app)
{
TokenValidationParameters tvps = new TokenValidationParameters
{
// Accept only those tokens where the audience of the token is equal to the client ID of this app
ValidAudience = ClientId,
AuthenticationType = Startup.DefaultPolicy
};

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, DefaultPolicy)))
});
}

关于azure - 将 Owin.Security.ActiveDirectory 库与 AAD B2C 一起使用是否正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43716170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com