-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1649f98
commit bbafaed
Showing
55 changed files
with
1,113 additions
and
428 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
using System.Collections.Generic; | ||
using System.Security.Claims; | ||
|
||
namespace DPoPApi; | ||
|
||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Duende.IdentityServer" Version="6.3.5" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.0" /> | ||
<PackageReference Include="Serilog.AspNetCore" Version="6.0.0" /> | ||
<PackageReference Include="Duende.IdentityServer" Version="7.0.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" /> | ||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" /> | ||
</ItemGroup> | ||
</Project> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@page | ||
@model IdentityServerHost.Pages.Create.Index | ||
|
||
<div class="login-page"> | ||
<div class="lead"> | ||
<h1>Create Account</h1> | ||
</div> | ||
|
||
<partial name="_ValidationSummary" /> | ||
|
||
<div class="row"> | ||
|
||
<div class="col-sm-6"> | ||
<form asp-page="/Account/Create/Index"> | ||
<input type="hidden" asp-for="Input.ReturnUrl" /> | ||
|
||
<div class="form-group"> | ||
<label asp-for="Input.Username"></label> | ||
<input class="form-control" placeholder="Username" asp-for="Input.Username" autofocus> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Input.Password"></label> | ||
<input type="password" class="form-control" placeholder="Password" asp-for="Input.Password" autocomplete="off"> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Input.Name"></label> | ||
<input type="text" class="form-control" placeholder="Name" asp-for="Input.Name"> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="Input.Email"></label> | ||
<input type="email" class="form-control" placeholder="Email" asp-for="Input.Email" > | ||
</div> | ||
|
||
<button class="btn btn-primary" name="Input.Button" value="create">Create</button> | ||
<button class="btn btn-secondary" name="Input.Button" value="cancel">Cancel</button> | ||
</form> | ||
</div> | ||
|
||
</div> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
using Duende.IdentityServer; | ||
using Duende.IdentityServer.Models; | ||
using Duende.IdentityServer.Services; | ||
using Duende.IdentityServer.Test; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace IdentityServerHost.Pages.Create; | ||
|
||
[SecurityHeaders] | ||
[AllowAnonymous] | ||
public class Index : PageModel | ||
{ | ||
private readonly TestUserStore _users; | ||
private readonly IIdentityServerInteractionService _interaction; | ||
|
||
[BindProperty] | ||
public InputModel Input { get; set; } = default!; | ||
|
||
public Index( | ||
IIdentityServerInteractionService interaction, | ||
TestUserStore? users = null) | ||
{ | ||
// this is where you would plug in your own custom identity management library (e.g. ASP.NET Identity) | ||
_users = users ?? throw new InvalidOperationException("Please call 'AddTestUsers(TestUsers.Users)' on the IIdentityServerBuilder in Startup or remove the TestUserStore from the AccountController."); | ||
|
||
_interaction = interaction; | ||
} | ||
|
||
public IActionResult OnGet(string? returnUrl) | ||
{ | ||
Input = new InputModel { ReturnUrl = returnUrl }; | ||
return Page(); | ||
} | ||
|
||
public async Task<IActionResult> OnPost() | ||
{ | ||
// check if we are in the context of an authorization request | ||
var context = await _interaction.GetAuthorizationContextAsync(Input.ReturnUrl); | ||
|
||
// the user clicked the "cancel" button | ||
if (Input.Button != "create") | ||
{ | ||
if (context != null) | ||
{ | ||
// if the user cancels, send a result back into IdentityServer as if they | ||
// denied the consent (even if this client does not require consent). | ||
// this will send back an access denied OIDC error response to the client. | ||
await _interaction.DenyAuthorizationAsync(context, AuthorizationError.AccessDenied); | ||
|
||
// we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null | ||
if (context.IsNativeClient()) | ||
{ | ||
// The client is native, so this change in how to | ||
// return the response is for better UX for the end user. | ||
return this.LoadingPage(Input.ReturnUrl); | ||
} | ||
|
||
return Redirect(Input.ReturnUrl ?? "~/"); | ||
} | ||
else | ||
{ | ||
// since we don't have a valid context, then we just go back to the home page | ||
return Redirect("~/"); | ||
} | ||
} | ||
|
||
if (_users.FindByUsername(Input.Username) != null) | ||
{ | ||
ModelState.AddModelError("Input.Username", "Invalid username"); | ||
} | ||
|
||
if (ModelState.IsValid) | ||
{ | ||
var user = _users.CreateUser(Input.Username, Input.Password, Input.Name, Input.Email); | ||
|
||
// issue authentication cookie with subject ID and username | ||
var isuser = new IdentityServerUser(user.SubjectId) | ||
{ | ||
DisplayName = user.Username | ||
}; | ||
|
||
await HttpContext.SignInAsync(isuser); | ||
|
||
if (context != null) | ||
{ | ||
if (context.IsNativeClient()) | ||
{ | ||
// The client is native, so this change in how to | ||
// return the response is for better UX for the end user. | ||
return this.LoadingPage(Input.ReturnUrl); | ||
} | ||
|
||
// we can trust Input.ReturnUrl since GetAuthorizationContextAsync returned non-null | ||
return Redirect(Input.ReturnUrl ?? "~/"); | ||
} | ||
|
||
// request for a local page | ||
if (Url.IsLocalUrl(Input.ReturnUrl)) | ||
{ | ||
return Redirect(Input.ReturnUrl); | ||
} | ||
else if (string.IsNullOrEmpty(Input.ReturnUrl)) | ||
{ | ||
return Redirect("~/"); | ||
} | ||
else | ||
{ | ||
// user might have clicked on a malicious link - should be logged | ||
throw new ArgumentException("invalid return URL"); | ||
} | ||
} | ||
|
||
return Page(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Duende Software. All rights reserved. | ||
// See LICENSE in the project root for license information. | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace IdentityServerHost.Pages.Create; | ||
|
||
public class InputModel | ||
{ | ||
[Required] | ||
public string? Username { get; set; } | ||
|
||
[Required] | ||
public string? Password { get; set; } | ||
|
||
public string? Name { get; set; } | ||
public string? Email { get; set; } | ||
|
||
public string? ReturnUrl { get; set; } | ||
|
||
public string? Button { get; set; } | ||
} |
Oops, something went wrong.