Authorization has been denied for this request - B2C OAuthBearerAuthenticationOptions

Viewed 175

I've followed a tutorial where with Postman we can connect to our API. The Postman returns a Bearer token, but when I try to test the api I keep getting the Authorization has been denied for this request error.

enter image description here

I think it connects ok to the Azure portal, since I'm getting the token ok.

I have this in the Startup.class

    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;

 public void Configuration(IAppBuilder app)
 {
    ConfigureAuth(app);   
    ....        
 }
 private 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,
            NameClaimType = "name",
            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)))
        });
}

Any advise is appreciated.

0 Answers
Related