title: IdentityServer3 and Web API in same process
body: <p>I have Asp.net MVC web application and webapi in same project.I am using Resource owner Credential flow to have identity management.Is it possible to configure webapi, client and identity server in same startup.cs(startup.cs of webapplication).While trying to configure webapi and identity server in same startup.cs i ended up with the following error <strong><em>"An exception of type 'System.InvalidOperationException' occurred in IdentityServer3.AccessTokenValidation.dll but was not handled in user code
  Additional information: IDX10803: Unable to create to obtain configuration from: '<a href="https://localhost:44303/.well-known/openid-configuration" rel="nofollow">https://localhost:44303/.well-known/openid-configuration</a>'."</em></strong> </p>
  
  <p>Here is the code of my startup.cs:</p>
  
  <pre><code>using IdentityServer3.AccessTokenValidation;
  using IdentityServer3.Core.Configuration;
  using IdentityServer3.Core.Services;
  using IdentityServer3.Core.Services.Default;
  using MarilynIdentityServer.IdentityServer;
  using Microsoft.Owin;
  using Owin;
  using System;
  //using System.IdentityModel.Claims;
  using System.Security.Claims;
  using System.Security.Cryptography.X509Certificates;
  using System.Threading.Tasks;
  using System.Web.Http;
  using System.Linq;
  
  [assembly: OwinStartupAttribute(typeof(MarilynIdentityServer.Startup))]
  namespace MarilynIdentityServer
  {
      public class Startup
      {
          public void Configuration(IAppBuilder app)
          {
  
              var factory = new IdentityServerServiceFactory()
                      .UseInMemoryClients(Clients.Get())
                      .UseInMemoryScopes(Scopes.Get());   
  
              var userService = new UserLoginService();
  
              factory.UserService = new Registration&lt;IUserService&gt;(resolver =&gt; userService);
              factory.CorsPolicyService = new Registration&lt;ICorsPolicyService&gt;(new DefaultCorsPolicyService { AllowAll = true });
  
              var option = new IdentityServerOptions
              {
  
  
                  SiteName = "Embedded IdentityServer",
                  SigningCertificate = LoadCertificate(),
  
                  Factory = factory,
  
                  //AuthenticationOptions = new AuthenticationOptions
                  //{
                  //    //EnableLocalLogin = false,
                  //    IdentityProviders = ConfigureIdentityProviders
                  //},
  
  
              };
              app.UseIdentityServer(option);
  
  
              app.Map("/api", idsrvApi =&gt;
              {
                  // token validation
                  idsrvApi.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
                  {
                      Authority = "https://localhost:44303/",
                      RequiredScopes = new[] { "sampleApi" }
                  });
  
                  // add app local claims per request
                  idsrvApi.UseClaimsTransformation(incoming =&gt;
                  {
                      // either add claims to incoming, or create new principal
                      var appPrincipal = new ClaimsPrincipal(incoming);
                      incoming.Identities.First().AddClaim(new Claim("appSpecific", "some_value"));
  
                      return Task.FromResult(appPrincipal);
                  });
  
                  // web api configuration
                  var config = new HttpConfiguration();
                  config.MapHttpAttributeRoutes();
  
                  idsrvApi.UseWebApi(config);
              });
          }
  
          X509Certificate2 LoadCertificate()
          {  
  
              return new X509Certificate2(
                  string.Format(@"{0}bin\identityServer\idsrv3test.pfx", AppDomain.CurrentDomain.BaseDirectory), "idsrv3test");
  
  
          }
      }
  }
  </code></pre>
  
  <p>To conclude Is it possible to configure WebApi, Webapplication and Identity Server in same application?</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Regards
  Amit  </p>