Skip to content

Commit 0467c83

Browse files
Merge pull request #39 from RockSolidKnowledge/updateForRazorPages
Update for razor pages
2 parents 9d7bd20 + 3b2f593 commit 0467c83

File tree

239 files changed

+21742
-4362
lines changed

Some content is hidden

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

239 files changed

+21742
-4362
lines changed
Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,52 @@
1-
// Copyright (c) Duende Software. All rights reserved.
2-
// See LICENSE in the project root for license information.
1+
using Duende.IdentityServer.Models;
32

3+
namespace DuendeDynamicProviders;
44

5-
using Duende.IdentityServer.Models;
6-
using System.Collections.Generic;
7-
using Duende.IdentityServer;
8-
9-
namespace DuendeDynamicProviders
5+
public static class Config
106
{
11-
public static class Config
12-
{
13-
public static IEnumerable<IdentityResource> GetIdentityResources()
7+
public static IEnumerable<IdentityResource> IdentityResources =>
8+
new IdentityResource[]
149
{
15-
return new IdentityResource[]
16-
{
17-
new IdentityResources.OpenId(),
18-
new IdentityResources.Profile(),
19-
};
20-
}
10+
new IdentityResources.OpenId(),
11+
new IdentityResources.Profile(),
12+
};
2113

22-
public static IEnumerable<ApiResource> GetApis()
14+
public static IEnumerable<ApiScope> ApiScopes =>
15+
new ApiScope[]
2316
{
24-
return new ApiResource[]
25-
{
26-
new ApiResource("api1", "My API #1")
27-
};
28-
}
17+
new ApiScope("scope1"),
18+
new ApiScope("scope2"),
19+
};
2920

30-
public static IEnumerable<ApiScope> GetApiScopes()
21+
public static IEnumerable<Client> Clients =>
22+
new Client[]
3123
{
32-
return new ApiScope[]
24+
// m2m client credentials flow client
25+
new Client
3326
{
34-
new ApiScope("scope1"),
35-
new ApiScope("scope2"),
36-
};
37-
}
38-
39-
public static IEnumerable<Client> GetClients()
40-
{
41-
return new[]
27+
ClientId = "m2m.client",
28+
ClientName = "Client Credentials Client",
29+
30+
AllowedGrantTypes = GrantTypes.ClientCredentials,
31+
ClientSecrets = { new Secret("511536EF-F270-4058-80CA-1C89C192F69A".Sha256()) },
32+
33+
AllowedScopes = { "scope1" }
34+
},
35+
36+
// interactive client using code flow + pkce
37+
new Client
4238
{
43-
new Client
44-
{
45-
ClientId = "https://localhost:5002",
46-
ClientName = "client",
47-
ProtocolType = IdentityServerConstants.ProtocolTypes.OpenIdConnect,
48-
AllowedScopes = {"openid", "profile"}
49-
}
50-
};
51-
}
52-
}
53-
}
39+
ClientId = "interactive",
40+
ClientSecrets = { new Secret("49C1A7E1-0C79-4A89-A3D6-A37998FB86B0".Sha256()) },
41+
42+
AllowedGrantTypes = GrantTypes.Code,
43+
44+
RedirectUris = { "https://localhost:44300/signin-oidc" },
45+
FrontChannelLogoutUri = "https://localhost:44300/signout-oidc",
46+
PostLogoutRedirectUris = { "https://localhost:44300/signout-callback-oidc" },
47+
48+
AllowOfflineAccess = true,
49+
AllowedScopes = { "openid", "profile", "scope2" }
50+
},
51+
};
52+
}

DuendeIdentityServer/DuendeDynamicProviders/DuendeDynamicProviders.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
56
</PropertyGroup>
67

7-
<ItemGroup>
8+
<ItemGroup>
89
<PackageReference Include="Duende.IdentityServer" Version="6.0.0" />
910
<PackageReference Include="Rsk.Saml" Version="5.0.0" />
1011
<PackageReference Include="Rsk.Saml.DuendeIdentityServer" Version="6.0.0" />
1112

12-
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
13+
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
1314
</ItemGroup>
1415

1516
<ItemGroup>
16-
<None Update="testclient.cer">
17+
<None Update="idsrv3test.cer">
1718
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1819
</None>
19-
<None Update="testclient.pfx">
20+
<None Update="testclient.cer">
2021
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2122
</None>
22-
<None Update="idsrv3test.cer">
23-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
24-
</None>
2523
</ItemGroup>
2624

25+
26+
2727
</Project>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System.Security.Cryptography.X509Certificates;
2+
using Duende.IdentityServer;
3+
using Rsk.AspNetCore.Authentication.Saml2p;
4+
using Rsk.Saml.DuendeIdentityServer.DynamicProviders;
5+
using Serilog;
6+
7+
namespace DuendeDynamicProviders;
8+
9+
internal static class HostingExtensions
10+
{
11+
public static WebApplication ConfigureServices(this WebApplicationBuilder builder)
12+
{
13+
builder.Services.AddRazorPages();
14+
15+
var isBuilder = builder.Services.AddIdentityServer(options =>
16+
{
17+
options.Events.RaiseErrorEvents = true;
18+
options.Events.RaiseInformationEvents = true;
19+
options.Events.RaiseFailureEvents = true;
20+
options.Events.RaiseSuccessEvents = true;
21+
22+
// see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/
23+
options.EmitStaticAudienceClaim = true;
24+
})
25+
.AddTestUsers(TestUsers.Users);
26+
27+
// in-memory, code config
28+
isBuilder.AddInMemoryIdentityResources(Config.IdentityResources);
29+
isBuilder.AddInMemoryApiScopes(Config.ApiScopes);
30+
isBuilder.AddInMemoryClients(Config.Clients);
31+
32+
// SP configuration - dynamic providers
33+
isBuilder.AddSamlDynamicProvider(options =>
34+
{
35+
// unstorable/reusable data, such as license information and events. This will override the data stored
36+
options.Licensee = "/* your DEMO Licensee */";
37+
options.LicenseKey = "/* your DEMO LicenseKey */";
38+
})
39+
40+
// Use EntityFramework store for storing identity providers
41+
//.AddIdentityProviderStore<SamlIdentityProviderStore>();
42+
43+
// use in memory store for storing identity providers
44+
.AddInMemoryIdentityProviders(new List<SamlDynamicIdentityProvider>
45+
{
46+
new SamlDynamicIdentityProvider
47+
{
48+
SamlAuthenticationOptions = new Saml2pAuthenticationOptions
49+
{
50+
// The IdP you want to integrate with
51+
IdentityProviderOptions = new IdpOptions
52+
{
53+
EntityId = "https://localhost:5000",
54+
SigningCertificates = { new X509Certificate2("idsrv3test.cer") },
55+
SingleSignOnEndpoint = new SamlEndpoint("https://localhost:5000/saml/sso", SamlBindingTypes.HttpRedirect),
56+
SingleLogoutEndpoint = new SamlEndpoint("https://localhost:5000/saml/slo", SamlBindingTypes.HttpRedirect)
57+
},
58+
59+
// Details about yourself (the SP)
60+
ServiceProviderOptions = new SpOptions
61+
{
62+
EntityId = "https://localhost:5004/saml",
63+
MetadataPath = "/federation/saml/metadata",
64+
SignAuthenticationRequests = false // OPTIONAL - use if you want to sign your auth requests
65+
},
66+
67+
NameIdClaimType = "sub",
68+
CallbackPath = "/federation/saml/signin-saml", // Duende prefixes "/federation/{scheme}" to all paths
69+
SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,
70+
},
71+
72+
Scheme = "saml",
73+
DisplayName = "saml",
74+
Enabled = true,
75+
}
76+
});
77+
78+
builder.Services.AddAuthentication();
79+
80+
return builder.Build();
81+
}
82+
83+
public static WebApplication ConfigurePipeline(this WebApplication app)
84+
{
85+
app.UseSerilogRequestLogging();
86+
87+
app.UseDeveloperExceptionPage();
88+
89+
app.UseStaticFiles();
90+
app.UseRouting();
91+
app.UseIdentityServer();
92+
app.UseAuthorization();
93+
94+
app.MapRazorPages()
95+
.RequireAuthorization();
96+
97+
return app;
98+
}
99+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@page
2+
@model DuendeDynamicProviders.Pages.Account.AccessDeniedModel
3+
@{
4+
}
5+
<div class="row">
6+
<div class="col">
7+
<h1>Access Denied</h1>
8+
<p>You do not have permission to access that resource.</p>
9+
</div>
10+
</div>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace DuendeDynamicProviders.Pages.Account
5+
{
6+
public class AccessDeniedModel : PageModel
7+
{
8+
public void OnGet()
9+
{
10+
}
11+
}
12+
}

DuendeIdentityServer/DuendeIdP/Views/Account/Login.cshtml renamed to DuendeIdentityServer/DuendeDynamicProviders/Pages/Account/Login/Index.cshtml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@model LoginViewModel
1+
@page
2+
@model DuendeDynamicProviders.Pages.Login.Index
23

34
<div class="login-page">
45
<div class="lead">
@@ -10,7 +11,7 @@
1011

1112
<div class="row">
1213

13-
@if (Model.EnableLocalLogin)
14+
@if (Model.View.EnableLocalLogin)
1415
{
1516
<div class="col-sm-6">
1617
<div class="card">
@@ -19,37 +20,39 @@
1920
</div>
2021

2122
<div class="card-body">
22-
<form asp-route="Login">
23-
<input type="hidden" asp-for="ReturnUrl" />
23+
<form asp-page="/Account/Login/Index">
24+
<input type="hidden" asp-for="Input.ReturnUrl" />
2425

2526
<div class="form-group">
26-
<label asp-for="Username"></label>
27-
<input class="form-control" placeholder="Username" asp-for="Username" autofocus>
27+
<label asp-for="Input.Username"></label>
28+
<input class="form-control" placeholder="Username" asp-for="Input.Username" autofocus>
2829
</div>
2930
<div class="form-group">
30-
<label asp-for="Password"></label>
31-
<input type="password" class="form-control" placeholder="Password" asp-for="Password" autocomplete="off">
31+
<label asp-for="Input.Password"></label>
32+
<input type="password" class="form-control" placeholder="Password" asp-for="Input.Password" autocomplete="off">
3233
</div>
33-
@if (Model.AllowRememberLogin)
34+
35+
@if (Model.View.AllowRememberLogin)
3436
{
3537
<div class="form-group">
3638
<div class="form-check">
37-
<input class="form-check-input" asp-for="RememberLogin">
38-
<label class="form-check-label" asp-for="RememberLogin">
39+
<input class="form-check-input" asp-for="Input.RememberLogin">
40+
<label class="form-check-label" asp-for="Input.RememberLogin">
3941
Remember My Login
4042
</label>
4143
</div>
4244
</div>
4345
}
44-
<button class="btn btn-primary" name="button" value="login">Login</button>
45-
<button class="btn btn-secondary" name="button" value="cancel">Cancel</button>
46+
47+
<button class="btn btn-primary" name="Input.Button" value="login">Login</button>
48+
<button class="btn btn-secondary" name="Input.Button" value="cancel">Cancel</button>
4649
</form>
4750
</div>
4851
</div>
4952
</div>
5053
}
5154

52-
@if (Model.VisibleExternalProviders.Any())
55+
@if (Model.View.VisibleExternalProviders.Any())
5356
{
5457
<div class="col-sm-6">
5558
<div class="card">
@@ -58,14 +61,13 @@
5861
</div>
5962
<div class="card-body">
6063
<ul class="list-inline">
61-
@foreach (var provider in Model.VisibleExternalProviders)
64+
@foreach (var provider in Model.View.VisibleExternalProviders)
6265
{
6366
<li class="list-inline-item">
6467
<a class="btn btn-secondary"
65-
asp-controller="External"
66-
asp-action="Challenge"
68+
asp-page="/ExternalLogin/Challenge"
6769
asp-route-scheme="@provider.AuthenticationScheme"
68-
asp-route-returnUrl="@Model.ReturnUrl">
70+
asp-route-returnUrl="@Model.Input.ReturnUrl">
6971
@provider.DisplayName
7072
</a>
7173
</li>
@@ -76,7 +78,7 @@
7678
</div>
7779
}
7880

79-
@if (!Model.EnableLocalLogin && !Model.VisibleExternalProviders.Any())
81+
@if (!Model.View.EnableLocalLogin && !Model.View.VisibleExternalProviders.Any())
8082
{
8183
<div class="alert alert-warning">
8284
<strong>Invalid login request</strong>

0 commit comments

Comments
 (0)