Created
August 13, 2018 02:20
-
-
Save componentspace/49b98a772a2b292360d473576e568f10 to your computer and use it in GitHub Desktop.
IdentityServer4 as a SAML SP using ComponentSpace - Startup class
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
using IdentityServer4; | |
using IdentityServer4.Models; | |
using IdentityServer4.Services; | |
using IdentityServer4.Stores; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using System; | |
namespace TestIdentityServer4 | |
{ | |
public class Startup | |
{ | |
private readonly IConfiguration _config; | |
public Startup(IConfiguration config) | |
{ | |
_config = config; | |
} | |
// 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.AddMvc(); | |
services.AddIdentityServer() | |
.AddDeveloperSigningCredential() | |
.AddInMemoryIdentityResources(Config.GetIdentityResources()) | |
.AddInMemoryApiResources(Config.GetApiResources()) | |
.AddInMemoryClients(Config.GetClients()) | |
.AddTestUsers(Config.GetUsers()); | |
// Add SAML SSO services. | |
services.AddSaml(_config.GetSection("SAML")); | |
services.AddAuthentication() | |
.AddSaml(options => | |
{ | |
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; | |
options.PartnerName = () => _config["PartnerName"]; | |
}); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseIdentityServer(); | |
app.UseStaticFiles(); | |
app.UseMvcWithDefaultRoute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment