title: IdentityServer4 Invalid Redirect_Uri Error
body: <p>I created 3 separate projects, web api project, an web mvc project, and a asp.net core app. I am using IdentityServer4 with asp.net core identity. I have a project solution <code>id</code> that has the information of the <code>TestUsers</code>. On the line <code>RedirectUris = {&quot;https://localhost:5444/signin-oidc&quot;}</code>, I am redirecting it to the project <code>WeatherMVC</code>. The launchsettings.json on all three files are correct and so is the <code>RedirectUris</code> is correct. <strong>Is there something that I am not doing correctly that is causing me to receive this message?</strong></p>
  <p><a href="https://i.stack.imgur.com/tVGp8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tVGp8.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/y7DMt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/y7DMt.png" alt="enter image description here" /></a></p>
  <p><strong><code>weatherapi project</code>:</strong></p>
  <p><code>----startup.cs</code>:</p>
  <pre><code>namespace weatherapi
  {
      public class Startup
      {
          public Startup(IConfiguration configuration)
          {
              Configuration = configuration;
          }
  
          public IConfiguration Configuration { get; }
  
          // This method gets called by the runtime. Use this method to add services to the container.
  
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddAuthentication(&quot;Bearer&quot;)
                  .AddIdentityServerAuthentication(&quot;Bearer&quot;, options =&gt;
                  {
                      options.ApiName = &quot;weatherapi&quot;;
                      options.Authority = &quot;https://localhost:5443&quot;;
                  });
  
              services.AddControllers();
  
              services.AddSwaggerGen(c =&gt;
              {
                  c.SwaggerDoc(&quot;v1&quot;, new OpenApiInfo { Title = &quot;weatherapi&quot;, Version = &quot;v1&quot; });
              });
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
                  app.UseSwagger();
                  app.UseSwaggerUI(c =&gt; c.SwaggerEndpoint(&quot;/swagger/v1/swagger.json&quot;, &quot;weatherapi v1&quot;));
              }
  
              app.UseHttpsRedirection();
  
              app.UseRouting();
  
              app.UseAuthentication();
              app.UseAuthorization();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllers();
              });
          }
      }
  }
  </code></pre>
  <p><code>----launchsettings.json</code>:</p>
  <pre><code>{
    &quot;$schema&quot;: &quot;http://json.schemastore.org/launchsettings.json&quot;,
    &quot;iisSettings&quot;: {
      &quot;windowsAuthentication&quot;: false,
      &quot;anonymousAuthentication&quot;: true,
      &quot;iisExpress&quot;: {
        &quot;applicationUrl&quot;: &quot;http://localhost:52575&quot;,
        &quot;sslPort&quot;: 44354
      }
    },
    &quot;profiles&quot;: {
      &quot;IIS Express&quot;: {
        &quot;commandName&quot;: &quot;IISExpress&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;launchUrl&quot;: &quot;swagger&quot;,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        }
      },
      &quot;weatherapi&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;dotnetRunMessages&quot;: &quot;true&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;hotReloadProfile&quot;: &quot;aspnetcore&quot;,
        &quot;launchUrl&quot;: &quot;swagger&quot;,
        &quot;applicationUrl&quot;: &quot;https://localhost:5445;http://localhost:5002&quot;,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        }
      }
    }
  }
  </code></pre>
  <p><strong><code>WeatherMVC Project</code></strong>:</p>
  <p><code>----launchsettings.json</code>:</p>
  <pre><code>{
    &quot;iisSettings&quot;: {
      &quot;windowsAuthentication&quot;: false,
      &quot;anonymousAuthentication&quot;: true,
      &quot;iisExpress&quot;: {
        &quot;applicationUrl&quot;: &quot;http://localhost:65206&quot;,
        &quot;sslPort&quot;: 44398
      }
    },
    &quot;profiles&quot;: {
      &quot;IIS Express&quot;: {
        &quot;commandName&quot;: &quot;IISExpress&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        }
      },
      &quot;WeatherMVC&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        },
        &quot;dotnetRunMessages&quot;: &quot;true&quot;,
        &quot;applicationUrl&quot;: &quot;https://localhost:5444;http://localhost:5001&quot;
      }
    }
  }
  </code></pre>
  <p>These two projects are under one solution which I perform a multiple startup projects.</p>
  <p>On the other project, named <code>id</code>...</p>
  <p><strong><code>id project</code></strong>:</p>
  <p><code>----launchsettings.json</code></p>
  <pre><code>{
    &quot;iisSettings&quot;: {
      &quot;windowsAuthentication&quot;: false,
      &quot;anonymousAuthentication&quot;: true,
      &quot;iisExpress&quot;: {
        &quot;applicationUrl&quot;: &quot;http://localhost:19916&quot;,
        &quot;sslPort&quot;: 44341
      }
    },
    &quot;profiles&quot;: {
      &quot;IIS Express&quot;: {
        &quot;commandName&quot;: &quot;IISExpress&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        }
      },
      &quot;id&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;launchBrowser&quot;: true,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        },
        &quot;hotReloadProfile&quot;: &quot;aspnetcore&quot;,
        &quot;dotnetRunMessages&quot;: &quot;true&quot;,
        &quot;applicationUrl&quot;: &quot;https://localhost:5443;http://localhost:5000&quot;
      }
    }
  }
  </code></pre>
  <p><strong>inside of this class below <code>Config.cs</code>, I have the code where it will perform the <code>Redirect_uri</code></strong>:</p>
  <pre><code>        public static IEnumerable&lt;Client&gt; Clients =&gt;
            new[]
            {
          // m2m client credentials flow client
          new Client
          {
            ClientId = &quot;m2m.client&quot;,
            ClientName = &quot;Client Credentials Client&quot;,
  
            AllowedGrantTypes = GrantTypes.ClientCredentials,
            ClientSecrets = {new Secret(&quot;SuperSecretPassword&quot;.Sha256())},
  
            AllowedScopes = {&quot;weatherapi.read&quot;, &quot;weatherapi.write&quot;}
          },
  
          // interactive client using code flow + pkce
          new Client
          {
            ClientId = &quot;interactive&quot;,
            ClientSecrets = {new Secret(&quot;SuperSecretPassword&quot;.Sha256())},
  
            AllowedGrantTypes = GrantTypes.Code,
  
            RedirectUris = {&quot;https://localhost:5444/signin-oidc&quot;},
            FrontChannelLogoutUri = &quot;https://localhost:5444/signout-oidc&quot;,
            PostLogoutRedirectUris = {&quot;https://localhost:5444/signout-callback-oidc&quot;},
  
            AllowOfflineAccess = true,
            AllowedScopes = {&quot;openid&quot;, &quot;profile&quot;, &quot;weatherapi.read&quot;},
            RequirePkce = true,
            RequireConsent = true,
            AllowPlainTextPkce = false
          },
            };
      }
  }
  </code></pre>
  <p><code>----startup.cs</code>:</p>
  <pre><code>public class Startup
      {
          // This method gets called by the runtime. Use this method to add services to the container.
          // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddIdentityServer()
                  .AddInMemoryClients(Config.Clients)
                  .AddInMemoryIdentityResources(Config.IdentityResources)
                  .AddInMemoryApiResources(Config.ApiResources)
                  .AddInMemoryApiScopes(Config.ApiScopes)
                  .AddTestUsers(Config.Users)
                  .AddDeveloperSigningCredential();
  
              services.AddControllersWithViews();
          }
  
          // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseRouting();
              app.UseStaticFiles();
              app.UseIdentityServer();
              app.UseAuthorization();
  
             app.UseEndpoints(endpoints =&gt; endpoints.MapDefaultControllerRoute());
  
          }
      }
  </code></pre>
  <hr />
  <p><em><strong>UPDATE</strong></em></p>
  <p>After adding the debugger in <code>program.cs</code> as suggested:</p>
  <pre><code>public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
          Host.CreateDefaultBuilder(args)
              .ConfigureWebHostDefaults(webBuilder =&gt;
              {
                  webBuilder.UseStartup&lt;Startup&gt;();
              })
              .ConfigureLogging(builder =&gt;
              {
                  builder.SetMinimumLevel(LogLevel.Debug);
                  builder.AddFilter(&quot;IdentityServer4&quot;, LogLevel.Debug);
              });
  </code></pre>
  <p>I finally noticed that it is calling the redirect uri that belongs to the project named <code>WeatherMVC</code> using it's <code>sslPort: 44398</code>. Please see the <code>launchsettings.json</code> for that <code>weathermvc projcect</code>. Can't seem to understand why it is redirecting that URI if I do not have it set to that.</p>
  <p><a href="https://i.stack.imgur.com/9y2S2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/9y2S2.png" alt="enter image description here" /></a></p>