tVoss42
tVoss42

Reputation: 582

How to run IdentityServer and WebAPI in same project

Currently I have an Identity server that runs perfectly, but I want to add an API on top of it to make some database configuration changes through a web front end. The examples in the docs show how to do this with MVC, but not WebAPI.

The Startup.Configuration method looks like this:

app.UseIdentityServer(new IdentityServerOptions{ ... });

...

app.Map("/api", apiApp =>
{
    apiApp.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
    {
        Authority = "https://localhost:44300", // URL of identity server
    });
});

However, when app.Map gets called, it throws an error because it can't reach the identity server, presumably because it hasn't started yet. How can I get them to properly work together?

Upvotes: 6

Views: 3666

Answers (1)

tVoss42
tVoss42

Reputation: 582

This always happens when I post on StackOverflow, I figured it out seconds after I posted! For anyone else having this issue, in the

IdentityServerBearerTokenAuthenticationOptions

set

DelayLoadMetadata = true

and then everything will run smoothly!

Upvotes: 15

Related Questions