对于ADFS身份提供程序,声明为空

时间:2018-10-30 07:52:35

标签: azure-ad-b2c claims-based-identity

我需要在我们的应用程序中设置B2C登录名。如果使用其他身份提供者,我会获得令牌,并且正确地在支持部分中获得了Claims,如您在此屏幕截图中所见

enter image description here

但是当我尝试使用ADFS时,来自Current.User的声明为空 我尝试使用ClaimsPrincipal.Current,但是Claims为空。 奇怪的是,在前端部分我可以正确获取令牌并且可以对其进行解码,我拥有所需的所有数据,但是在后端我无法获得声明。

enter image description here

我在Startup.Auth.cs文件中有此代码

public partial class Startup
{
    // These values are pulled from web.config
    public static string AadInstance = ConfigurationManager.AppSettings["ida:AadInstance"];
    public static string Tenant = ConfigurationManager.AppSettings["ida:Tenant"];
    public static string ClientId = ConfigurationManager.AppSettings["ida:ClientId"];
    public static string SignUpSignInPolicy = ConfigurationManager.AppSettings["ida:SignUpSignInPolicyId"];
    public static string DefaultPolicy = SignUpSignInPolicy;

    /*
     * Configure the authorization OWIN middleware 
     */
    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))),
        }
       );
    }
}

感谢您的帮助。

0 个答案:

没有答案