Created
May 24, 2019 14:22
-
-
Save oleksabor/75598f21d11ab903a8f6b986656f12a7 to your computer and use it in GitHub Desktop.
sample from IdentityServer4.Samples\Quickstarts\4_ImplicitFlowAuthenticationWithExternal\src\IdentityServer\
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
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. | |
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | |
using System; | |
using IdentityServer4; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.IdentityModel.Tokens; | |
namespace IdentityServer | |
{ | |
public class Startup | |
{ | |
public IHostingEnvironment Environment { get; } | |
public Startup(IHostingEnvironment environment) | |
{ | |
Environment = environment; | |
} | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1); | |
var builder = services.AddIdentityServer() | |
.AddInMemoryIdentityResources(Config.GetIdentityResources()) | |
.AddInMemoryApiResources(Config.GetApis()) | |
.AddInMemoryClients(Config.GetClients()) | |
.AddTestUsers(Config.GetUsers()); | |
if (Environment.IsDevelopment()) | |
{ | |
builder.AddDeveloperSigningCredential(); | |
} | |
else | |
{ | |
throw new Exception("need to configure key material"); | |
} | |
services.AddAuthentication() | |
/*.AddGoogle("Google", options => | |
{ | |
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; | |
options.ClientId = "<insert here>"; | |
options.ClientSecret = "<insert here>"; | |
}) */ | |
.AddOpenIdConnect("oidc", "OpenID Connect", options => | |
{ | |
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; | |
options.SignOutScheme = IdentityServerConstants.SignoutScheme; | |
options.SaveTokens = true; | |
options.Authority = "https://demo.identityserver.io/"; | |
options.ClientId = "implicit"; | |
options.TokenValidationParameters = new TokenValidationParameters | |
{ | |
NameClaimType = "name", | |
RoleClaimType = "role" | |
}; | |
}); | |
} | |
public void Configure(IApplicationBuilder app) | |
{ | |
if (Environment.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseStaticFiles(); | |
app.UseIdentityServer(); | |
app.UseMvcWithDefaultRoute(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is sample code I've downloaded from the IdentityServer4.Samples github project. However this project is not accessible any more. So I use this gist to share sample code and ask a question on StackOverflow.