Skip to content

Commit 40d9d1f

Browse files
committed
IdentityServer4-Demo
1 parent 5ccedb2 commit 40d9d1f

191 files changed

Lines changed: 73798 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,9 @@
120120
/权限管理/3-ASP.NET Identity/.vs/3-ASP.NET Identity/v15
121121
/EFCoreDemo/obj
122122
/EFCoreDemo/bin
123+
/sso(单点登录)/IdentityServer4_SSO_Service/IdentityServer4_SSO_Client1/bin
124+
/sso(单点登录)/IdentityServer4_SSO_Service/IdentityServer4_SSO_Service/bin
125+
/sso(单点登录)/IdentityServer4_SSO_Service/IdentityServer4_SSO_Client2/bin
126+
/sso(单点登录)/IdentityServer4_SSO_Service/IdentityServer4_SSO_Client2/obj
127+
/sso(单点登录)/IdentityServer4_SSO_Service/IdentityServer4_SSO_Service/obj
128+
/sso(单点登录)/IdentityServer4_SSO_Service/IdentityServer4_SSO_Client1/obj
Binary file not shown.

sso(单点登录)/IdentityServer4_SSO_Service/.vs/config/applicationhost.config

Lines changed: 1039 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "wwwroot/lib"
3+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.AspNetCore.Authentication;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Mvc;
4+
using System.Threading.Tasks;
5+
6+
namespace IdentityServer4_SSO_Client1.Controllers
7+
{
8+
public class HomeController : Controller
9+
{
10+
[Authorize]//身份认证
11+
public IActionResult Index()
12+
{
13+
return View();
14+
}
15+
16+
/// <summary>
17+
/// 登出
18+
/// </summary>
19+
/// <returns></returns>
20+
public async Task<IActionResult> Logout()
21+
{
22+
await HttpContext.SignOutAsync("Cookies");
23+
await HttpContext.SignOutAsync("oidc");
24+
return View("Index");
25+
}
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="IdentityModel" Version="2.14.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<Folder Include="Models\" />
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace IdentityServer4_SSO_Client1
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
BuildWebHost(args).Run();
18+
}
19+
20+
public static IWebHost BuildWebHost(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>()
23+
.Build();
24+
}
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:5002/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"IdentityServer4_SSO_Client1": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "http://localhost:19173/"
25+
}
26+
}
27+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using System.IdentityModel.Tokens.Jwt;
10+
11+
namespace IdentityServer4_SSO_Client1
12+
{
13+
public class Startup
14+
{
15+
public Startup(IConfiguration configuration)
16+
{
17+
Configuration = configuration;
18+
}
19+
20+
public IConfiguration Configuration { get; }
21+
22+
// This method gets called by the runtime. Use this method to add services to the container.
23+
public void ConfigureServices(IServiceCollection services)
24+
{
25+
services.AddMvc();
26+
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
27+
services.AddAuthentication(options =>
28+
{
29+
options.DefaultScheme = "Cookies";
30+
options.DefaultChallengeScheme = "oidc";
31+
}).AddCookie("Cookies").AddOpenIdConnect("oidc", options =>
32+
{
33+
options.SignInScheme = "Cookies";
34+
options.Authority = "http://localhost:5001";
35+
options.RequireHttpsMetadata = false;
36+
options.ClientId = "mvc1";
37+
options.ClientSecret = "secret";
38+
options.ResponseType = "code id_token";
39+
options.SaveTokens = true;
40+
options.GetClaimsFromUserInfoEndpoint = true;
41+
options.Scope.Add("api1");
42+
options.Scope.Add("offline_access");
43+
});
44+
}
45+
46+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
47+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
48+
{
49+
if (env.IsDevelopment())
50+
{
51+
app.UseDeveloperExceptionPage();
52+
}
53+
else
54+
{
55+
app.UseExceptionHandler("/Home/Error");
56+
}
57+
58+
app.UseAuthentication();
59+
60+
app.UseStaticFiles();
61+
app.UseMvcWithDefaultRoute();
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)