Last active
May 23, 2020 08:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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