Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Last active May 23, 2020 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/f83ab1b3fd54b735a8198e7927d42e5b to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/f83ab1b3fd54b735a8198e7927d42e5b to your computer and use it in GitHub Desktop.
Startup for Caller API to enable it to call another protected API
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddProtectedWebApi(Configuration)
.AddProtectedWebApiCallsProtectedWebApi(Configuration)
.AddInMemoryTokenCaches();
services.AddControllers();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
// NOTE: this is required for Angular Web App
// localhost:44380 is for WebAppAngular project
// localhost:4200 is required if you use angular CLI
// to create app and run it using ng serve
// You may want to add the caller API entry depending on your
// project configurations
app.UseCors(builder =>
{
builder.WithOrigins("https://localhost:44380")
.WithOrigins("http://localhost:4200")
.AllowCredentials()
.AllowAnyMethod()
.AllowAnyHeader();
});
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment