-
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.
Updated sample with public keys and signatures shown and started API …
…sample project for validating authentication non-client side.
- Loading branch information
1 parent
3a8d0ac
commit e8d139b
Showing
16 changed files
with
295 additions
and
27 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
15 changes: 15 additions & 0 deletions
15
...rStrube.Blazor.WebAuthentication.API/KristofferStrube.Blazor.WebAuthentication.API.csproj
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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
34 changes: 34 additions & 0 deletions
34
samples/KristofferStrube.Blazor.WebAuthentication.API/Program.cs
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,34 @@ | ||
using KristofferStrube.Blazor.WebAuthentication.API; | ||
|
||
WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
builder.Services.AddCors(o => o.AddPolicy("default", | ||
builder => | ||
builder.WithOrigins("https://localhost:7203", | ||
"https://kristofferstrube.github.io") | ||
.AllowAnyMethod() | ||
.AllowAnyHeader() | ||
)); | ||
|
||
WebApplication app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
_ = app | ||
.UseSwagger() | ||
.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseCors("default"); | ||
|
||
app.MapWebAuthenticationAPI(); | ||
|
||
app.Run(); |
41 changes: 41 additions & 0 deletions
41
samples/KristofferStrube.Blazor.WebAuthentication.API/Properties/launchSettings.json
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,41 @@ | ||
{ | ||
"$schema": "http:https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http:https://localhost:7664", | ||
"sslPort": 44311 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http:https://localhost:5079", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7259;http:https://localhost:5079", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
samples/KristofferStrube.Blazor.WebAuthentication.API/WebAuthenticationAPI.cs
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,23 @@ | ||
using Microsoft.AspNetCore.Http.HttpResults; | ||
using System.Security.Cryptography; | ||
|
||
namespace KristofferStrube.Blazor.WebAuthentication.API; | ||
|
||
public static class WebAuthenticationAPI | ||
{ | ||
public static IEndpointRouteBuilder MapWebAuthenticationAPI(this IEndpointRouteBuilder builder) | ||
{ | ||
RouteGroupBuilder group = builder | ||
.MapGroup("WebAuthentication"); | ||
|
||
_ = group.MapGet("Register/{userName}", Register) | ||
.WithName("Register"); | ||
|
||
return builder; | ||
} | ||
|
||
public static Ok<byte[]> Register(string userName) | ||
{ | ||
return TypedResults.Ok(RandomNumberGenerator.GetBytes(32)); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
samples/KristofferStrube.Blazor.WebAuthentication.API/appsettings.Development.json
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,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/KristofferStrube.Blazor.WebAuthentication.API/appsettings.json
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,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
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
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
18 changes: 18 additions & 0 deletions
18
samples/KristofferStrube.Blazor.WebAuthentication.WasmExample/WebAuthenticationClient.cs
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,18 @@ | ||
using System.Net.Http.Json; | ||
|
||
namespace KristofferStrube.Blazor.WebAuthentication.WasmExample; | ||
|
||
public class WebAuthenticationClient | ||
{ | ||
private readonly HttpClient httpClient; | ||
|
||
public WebAuthenticationClient([FromKeyedServices(typeof(WebAuthenticationClient))]HttpClient httpClient) | ||
{ | ||
this.httpClient = httpClient; | ||
} | ||
|
||
public async Task<byte[]?> Register(string userName) | ||
{ | ||
return await httpClient.GetFromJsonAsync<byte[]>($"Register/{userName}"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/KristofferStrube.Blazor.WebAuthentication/AuthenticatorAssertionResponse.cs
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,20 @@ | ||
using KristofferStrube.Blazor.WebIDL; | ||
using Microsoft.JSInterop; | ||
|
||
namespace KristofferStrube.Blazor.WebAuthentication; | ||
|
||
public class AuthenticatorAssertionResponse : AuthenticatorResponse, IJSCreatable<AuthenticatorAssertionResponse> | ||
{ | ||
public static Task<AuthenticatorAssertionResponse> CreateAsync(IJSRuntime jSRuntime, IJSObjectReference jSReference) | ||
{ | ||
return Task.FromResult<AuthenticatorAssertionResponse>(new(jSRuntime, jSReference)); | ||
} | ||
|
||
public AuthenticatorAssertionResponse(IJSRuntime jSRuntime, IJSObjectReference jSReference) : base(jSRuntime, jSReference) { } | ||
|
||
public async Task<IJSObjectReference> GetSignatureAsync() | ||
{ | ||
IJSObjectReference helper = await webAuthenticationHelperTask.Value; | ||
return await helper.InvokeAsync<IJSObjectReference>("getAttribute", JSReference, "signature"); | ||
} | ||
} |
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
Oops, something went wrong.