I would like to validate the token generated from IdentityServer in Web API(.Net Framework 4.7.1).
Here is what I've done so far in Startup.cs in Web API
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
RequireHttpsMetadata = false,
SignInAsAuthenticationType = "Cookies",
Authority = "https://localhost:44380/",
RedirectUri = "http://localhost:4200/auth-callback",
ClientId = "angular",
Scope = "api1",
ResponseType = "code"
});
}
It throws code challenge required error.
Due to the design constraint, I will not be able to use the IdentityServer/IdentityServer3.AccessTokenValidation and I should use UseOpenIdConnectAuthentication to validate the token.
Edit
I was able to get this working in Web API Core. Here is my Startup.cs of Web API Core. But not sure how to do this in Web API .Net Framework. I also tried with IdentityServer/IdentityServer3.AccessTokenValidation with below configuration but it throws 401 error
public void Configuration(IAppBuilder app)
{
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:44380",
RequiredScopes = new[] { "api1" }
});
}