Skip to content

Commit 01f8e93

Browse files
Ticket #771 : Add documentation
1 parent 3d8564a commit 01f8e93

29 files changed

Lines changed: 909 additions & 52 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7F9A3D8D-4217-4B6B-A18C-44E1CDC2CF82}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaApi", "src\TaApi\TaApi.csproj", "{10C9ADF1-A71F-453D-95EE-8A37E2832D86}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RpApi", "src\RpApi\RpApi.csproj", "{0EE90864-7273-4218-93C9-412607723BE5}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{10C9ADF1-A71F-453D-95EE-8A37E2832D86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{10C9ADF1-A71F-453D-95EE-8A37E2832D86}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{10C9ADF1-A71F-453D-95EE-8A37E2832D86}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{10C9ADF1-A71F-453D-95EE-8A37E2832D86}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{0EE90864-7273-4218-93C9-412607723BE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{0EE90864-7273-4218-93C9-412607723BE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{0EE90864-7273-4218-93C9-412607723BE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{0EE90864-7273-4218-93C9-412607723BE5}.Release|Any CPU.Build.0 = Release|Any CPU
29+
EndGlobalSection
30+
GlobalSection(NestedProjects) = preSolution
31+
{10C9ADF1-A71F-453D-95EE-8A37E2832D86} = {7F9A3D8D-4217-4B6B-A18C-44E1CDC2CF82}
32+
{0EE90864-7273-4218-93C9-412607723BE5} = {7F9A3D8D-4217-4B6B-A18C-44E1CDC2CF82}
33+
EndGlobalSection
34+
EndGlobal
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Authentication;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Mvc;
4+
using RpApi.ViewModels;
5+
6+
namespace RpApi.Controllers
7+
{
8+
public class ClaimsController : Controller
9+
{
10+
[Authorize]
11+
public async Task<IActionResult> Index()
12+
{
13+
var accessToken = await HttpContext.GetTokenAsync("access_token");
14+
return View(new ClaimsViewModel
15+
{
16+
AccessToken = accessToken
17+
});
18+
}
19+
}
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using RpApi.Models;
4+
5+
namespace RpApi.Controllers;
6+
7+
public class HomeController : Controller
8+
{
9+
private readonly ILogger<HomeController> _logger;
10+
11+
public HomeController(ILogger<HomeController> logger)
12+
{
13+
_logger = logger;
14+
}
15+
16+
public IActionResult Index()
17+
{
18+
return View();
19+
}
20+
21+
public IActionResult Privacy()
22+
{
23+
return View();
24+
}
25+
26+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
27+
public IActionResult Error()
28+
{
29+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
30+
}
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace RpApi.Models;
2+
3+
public class ErrorViewModel
4+
{
5+
public string? RequestId { get; set; }
6+
7+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
8+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using Microsoft.IdentityModel.Tokens;
2+
using SimpleIdServer.IdServer.Domains;
3+
using SimpleIdServer.OpenidFederation.Domains;
4+
using SimpleIdServer.OpenidFederation.Store.EF;
5+
using System.Security.Cryptography;
6+
7+
var builder = WebApplication.CreateBuilder(args);
8+
var signatureCredentials = new SigningCredentials(new RsaSecurityKey(RSA.Create()) { KeyId = "raId" }, SecurityAlgorithms.RsaSha256);
9+
10+
var jsonWebKey = signatureCredentials.SerializePublicJWK();
11+
jsonWebKey.Alg = SecurityAlgorithms.RsaSha256;
12+
jsonWebKey.Use = "sig";
13+
14+
builder.Services.AddDistributedMemoryCache();
15+
builder.Services.AddRpFederation(r =>
16+
{
17+
r.Client = new SimpleIdServer.IdServer.Domains.Client
18+
{
19+
ClientId = "http://localhost:7001",
20+
RedirectionUrls = new List<string>
21+
{
22+
"http://localhost:7001/signin-oidc"
23+
},
24+
ClientRegistrationTypesSupported = new List<string>
25+
{
26+
"automatic"
27+
},
28+
RequestObjectSigningAlg = SecurityAlgorithms.RsaSha256,
29+
Scopes = new List<Scope>
30+
{
31+
new Scope
32+
{
33+
Name = "openid"
34+
},
35+
new Scope
36+
{
37+
Name = "profile"
38+
}
39+
},
40+
ResponseTypes = new List<string>
41+
{
42+
"code"
43+
},
44+
GrantTypes = new List<string>
45+
{
46+
"authorization_code"
47+
},
48+
TokenEndPointAuthMethod = "private_key_jwt"
49+
};
50+
r.Client.Add(jsonWebKey.Kid, jsonWebKey, "sig", SecurityKeyTypes.RSA);
51+
r.SigningCredentials = signatureCredentials;
52+
});
53+
builder.Services.AddOpenidFederationStore();
54+
builder.Services.AddControllersWithViews();
55+
builder.Services.AddAuthentication(options =>
56+
{
57+
options.DefaultScheme = "Cookies";
58+
options.DefaultChallengeScheme = "sid";
59+
})
60+
.AddCookie("Cookies")
61+
.AddCustomOpenIdConnect("sid", options =>
62+
{
63+
64+
options.SignInScheme = "Cookies";
65+
options.ResponseType = "code";
66+
options.Authority = "https://localhost:5001/master";
67+
options.RequireHttpsMetadata = false;
68+
options.ClientId = "http://localhost:7001";
69+
options.GetClaimsFromUserInfoEndpoint = true;
70+
options.SaveTokens = true;
71+
options.UseFederationAutomaticRegistration(signatureCredentials);
72+
});
73+
74+
var app = builder.Build();
75+
AddTrustedEntities(app.Services);
76+
app.UseHttpsRedirection();
77+
app.UseStaticFiles();
78+
app.UseRouting();
79+
app.UseAuthorization();
80+
app.MapControllerRoute(
81+
name: "default",
82+
pattern: "{controller=Home}/{action=Index}/{id?}");
83+
84+
app.Run();
85+
static void AddTrustedEntities(IServiceProvider services)
86+
{
87+
using (var scope = services.CreateScope())
88+
{
89+
var dbContext = scope.ServiceProvider.GetRequiredService<OpenidFederationDbContext>();
90+
dbContext.FederationEntities.AddRange(new List<FederationEntity>
91+
{
92+
new FederationEntity
93+
{
94+
Id = Guid.NewGuid().ToString(),
95+
Sub = "http://localhost:7000",
96+
Realm = string.Empty,
97+
IsSubordinate = false
98+
}
99+
});
100+
dbContext.SaveChanges();
101+
}
102+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:65068",
8+
"sslPort": 44355
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"applicationUrl": "http://localhost:5272",
17+
"environmentVariables": {
18+
"ASPNETCORE_ENVIRONMENT": "Development"
19+
}
20+
},
21+
"https": {
22+
"commandName": "Project",
23+
"dotnetRunMessages": true,
24+
"launchBrowser": true,
25+
"applicationUrl": "https://localhost:7200;http://localhost:5272",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
},
30+
"IIS Express": {
31+
"commandName": "IISExpress",
32+
"launchBrowser": true,
33+
"environmentVariables": {
34+
"ASPNETCORE_ENVIRONMENT": "Development"
35+
}
36+
}
37+
}
38+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="SimpleIdServer.OpenIdConnect" Version="5.0.*-*" />
11+
<PackageReference Include="SimpleIdServer.OpenidFederation.Store.EF" Version="5.0.*-*" />
12+
<PackageReference Include="SimpleIdServer.Rp.Federation" Version="5.0.*-*" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace RpApi.ViewModels
2+
{
3+
public class ClaimsViewModel
4+
{
5+
public string AccessToken { get; set; }
6+
}
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@model RpApi.ViewModels.ClaimsViewModel
2+
3+
<ul>
4+
@foreach (var claim in User.Claims)
5+
{
6+
<li>@claim.Type : @claim.Value</li>
7+
}
8+
</ul>
9+
10+
<div>
11+
<h3>Access token</h3>
12+
<p>@Model.AccessToken</p>
13+
</div>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div class="text-center">
6+
<h1 class="display-4">Welcome</h1>
7+
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
8+
</div>

0 commit comments

Comments
 (0)