• Stars
    star
    2,718
  • Rank 16,766 (Top 0.4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Todo application with ASP.NET Core Blazor WASM, Minimal APIs and Authentication

Todo application with ASP.NET Core

CI

This is a Todo application that features:

  • Todo.Web - An ASP.NET Core hosted Blazor WASM front end application
  • TodoApi - An ASP.NET Core REST API backend using minimal APIs

image

It showcases:

  • Blazor WebAssembly
  • Minimal APIs
  • Using EntityFramework and SQLite for data access
  • OpenAPI
  • User management with ASP.NET Core Identity
  • Cookie authentication
  • JWT authentication
  • Proxying requests from the front end application server using YARP's IHttpForwarder
  • Rate Limiting
  • Writing integration tests for your REST API

Prerequisites

.NET

  1. Install .NET 7

Database

  1. Install the dotnet-ef tool: dotnet tool install dotnet-ef -g
  2. Navigate to the TodoApi folder.
    1. Run mkdir .db to create the local database folder.
    2. Run dotnet ef database update to create the database.
  3. Learn more about dotnet-ef

JWT

  1. To initialize the keys for JWT generation, run dotnet user-jwts in to TodoApi folder:

    dotnet user-jwts create
    

Running the application

To run the application, run both the Todo.Web/Server and TodoApi. Below are different ways to run both applications:

  • Visual Studio - Setup multiple startup projects by right clicking on the solution and selecting Properties. Select TodoApi and Todo.Web.Server as startup projects.

    image
  • Visual Studio Code - A compound launch definition is provided in the launch.json file, use the 'Run and Debug' view and select 'Web and API' and start that profile.

    image

  • Terminal/CLI - Open up 2 terminal windows, one in Todo.Web.Server and the other in TodoApi run:

    dotnet watch run -lp https
    

    This will run both applications with the https profile.

  • Tye - Install the global tool using the following command:

    dotnet tool install --global Microsoft.Tye --version 0.11.0-alpha.22111.1
    

    Run tye run in the repository root and navigate to the tye dashboard (usually http://localhost:8000) to see both applications running.

  • Docker Compose - Open your terminal, navigate to the root folder of this project and run the following commands:

    1. Build a docker image for the TodoApi directly from dotnet publish.

      dotnet publish ./TodoApi/TodoApi.csproj --os linux --arch x64 /t:PublishContainer -c Release
      
    2. Build a docker image for the Todo.Web.Server directly from dotnet publish.

      dotnet publish ./Todo.Web/Server/Todo.Web.Server.csproj --os linux --arch x64 /t:PublishContainer -c Release --self-contained true
      
    3. Generate certificate and configure local machine so we can start our apps with https support using docker compose.

      Windows using Linux containers

      set PASSWORD YourPasswordHere
      dotnet dev-certs https -ep ${HOME}/.aspnet/https/todoapps.pfx -p $PASSWORD --trust
      

      macOS or Linux

      export PASSWORD=YourPasswordHere
      dotnet dev-certs https -ep ~/.aspnet/https/todoapps.pfx -p $PASSWORD --trust
      
    4. Change these variables below in the docker-compose.yml file to match your https certificate and password.

      • ASPNETCORE_Kestrel__Certificates__Default__Password
      • ASPNETCORE_Kestrel__Certificates__Default__Path
    5. Run docker-compose up -d to spin up both apps todo-api and todo-web-server plus jaeger and prometheus.

    6. Navigate to the Todo Web app https://localhost:5003.

Optional

Using the API standalone

The Todo REST API can run standalone as well. You can run the TodoApi project and make requests to various endpoints using the Swagger UI (or a client of your choice):

image

Before executing any requests, you need to create a user and get an auth token.

  1. To create a new user, run the application and POST a JSON payload to /users endpoint:

    {
      "username": "myuser",
      "password": "<put a password here>"
    }
  2. To get a token for the above user run dotnet user-jwts to create a JWT token with the same user name specified above e.g:

    dotnet user-jwts create -n myuser
    
  3. You should be able to use this token to make authenticated requests to the todo endpoints.

  4. Learn more about user-jwts

Social authentication

In addition to username and password, social authentication providers can be configured to work with this todo application. By default it supports Github, Google, and Microsoft accounts.

Instructions for setting up each of these providers can be found at:

Once you obtain the client id and client secret, the configuration for these providers must be added with the following schema:

{
    "Authentication": {
        "Schemes": {
            "<scheme>": {
                "ClientId": "xxx",
                "ClientSecret": "xxxx"
            }
        }
    }
}

Or using environment variables:

Authentication__Schemes__<scheme>__ClientId=xxx
Authentication__Schemes__<scheme>__ClientSecret=xxx

Or using user secrets:

dotnet user-secrets set Authentication:Schemes:<scheme>:ClientId xxx
dotnet user-secrets set Authentication:Schemes:<scheme>:ClientSecret xxx

Other providers can be found here. These must be added to AuthenticationExtensions as well.

NOTE: Don't store client secrets in configuration!

Auth0

This sample has Auth0 configured as an OIDC server. It can be configured with the following schema:

{
  "Authentication": {
    "Schemes": {
      "Auth0": {
        "Audience": "<audience>",
        "Domain": "<domain>",
        "ClientId": "<client id>",
        "ClientSecret": "<client secret>"
      }
    }
  }
}

Learn more about the Auth0 .NET SDK here.

OpenTelemetry

TodoApi uses OpenTelemetry to collect logs, metrics and spans.

If you wish to view the collected telemetry, follow the steps below.

Metrics

  1. Run Prometheus with Docker:
docker run -d -p 9090:9090 --name prometheus -v $PWD/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
  1. Open Prometheus in your browser
  2. Query the collected metrics

Spans

  1. Configure environment variable OTEL_EXPORTER_OTLP_ENDPOINT with the right endpoint URL to enable .AddOtlpExporter below builder.Services.AddOpenTelemetryTracing, in the TodoApi/OpenTelemetryExtensions.cs file
  2. Run Jaeger with Docker:
docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 -e COLLECTOR_OTLP_ENABLED=true -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 4317:4317 -p 4318:4318 -p 14250:14250 -p 14268:14268 -p 14269:14269 -p 9411:9411 jaegertracing/all-in-one:latest
  1. Open Jaeger in your browser
  2. View the collected spans

More Repositories

1

AspNetCoreDiagnosticScenarios

This repository has examples of broken patterns in ASP.NET Core applications
C#
7,686
star
2

DotNetCodingPatterns

A collection of coding patterns in no particular order
1,357
star
3

Todos

Various todo list backend API implementations
C#
1,040
star
4

BedrockFramework

High performance, low level networking APIs for building custom servers and clients.
C#
1,038
star
5

Micronetes

Micronetes is a local orchestrator inspired by kubernetes that makes developing and testing microservices and distributed applications easier.
C#
773
star
6

TcpEcho

Basic TCP server that uses System.IO.Pipelines to parse line based messages
C#
352
star
7

Channels

Push based .NET Streams
C#
292
star
8

MultiProtocolAspNetCore

C#
251
star
9

TriviaR

A multiplayer trivia game using SignalR and .NET 7
C#
196
star
10

Roslyn.Reflection

Reflection APIs over roslyn symbol APIs
C#
185
star
11

YarpTunnelDemo

YARP demo showing how tunneling can be implemented over websockets
C#
161
star
12

QueryInterceptor

Provides a generic way to intercept IQueryable expression trees using custom expression visitors.
C#
159
star
13

uController

A source generator for minimal APIs
C#
159
star
14

CommandAndControl

A sample showing command and control using client results
HTML
158
star
15

IdentityEndpointsSample

A sample showing how to setup ASP.NET Core Identity API endpoints for authentication
C#
155
star
16

IISCrossover

A prototype running ASP.NET and ASP.NET Core in the same IIS pipeline
C#
138
star
17

Pubbie

A high performance pubsub client/server implementation for .NET Core
C#
132
star
18

NetStandard

A repository that describes the .NET Standard
C#
128
star
19

WebApplicationPlugins

A sample plugin model for ASP.NET Core applications
C#
119
star
20

eStoreLite

Simple eStore frontend backend application using ASP.NET Core
C#
106
star
21

WinDbgCheatSheet

This is a cheat sheet for windbg
104
star
22

BombRMan

A multiplayer bomberman clone written in JavaScript and C#
TypeScript
97
star
23

DotnetPerformanceTips

93
star
24

signalr-ports

JavaScript
92
star
25

NuGetPowerTools

A bunch of powershell modules that make it even easier to work with nuget
84
star
26

DynamicLinq

Dynamic LINQ queries based on C# 4 dynamic.
C#
83
star
27

WaitForDependenciesAspire

C#
81
star
28

HelloWorldVNext

Hello world applications on ASP.NET vNext
C#
79
star
29

SmartLoadBalancer

Sticky sessions without sticky sessions
C#
74
star
30

Scheduling

Experimenting with schedulers
C#
70
star
31

Jabbot

Bot API for JabbR
C#
66
star
32

AspireYarp

Yarp resource for Aspire.Hosting
C#
64
star
33

CacheR

A distributed cache implemented on top of SignalR
C#
63
star
34

UT3

C#
58
star
35

CommunityStandUpNet5

A set of samples show casing the .NET linker and .NET 5 APIs
C#
57
star
36

AspNetCoreRecipes

Recipes for common ASP.NET Core patterns
50
star
37

OwinHttpClient

Barebones http client that uses the owin interface built on .NET socket API.
C#
48
star
38

AspNetCoreOwinSample

A sample showing running OWIN based frameworks on top of ASP.NET Core
C#
47
star
39

MessengR

One on one messenger app using SignalR
JavaScript
45
star
40

EventGridDemo

C#
45
star
41

Streamer

JSON RPC over any bidirectional stream
C#
43
star
42

TcpProxy

A sample showing how to implement a tcp proxy using new kestrel APIs
C#
43
star
43

Build2024AspireDemo

HTML
43
star
44

AspireSwaggerUI

An aspire resource for showing swagger ui
C#
42
star
45

RestSample

C#
42
star
46

ServerStack

C#
36
star
47

Orleans.PubSub

A pub sub implementation built on top of orleans grains
C#
36
star
48

gRPCSamples

C#
34
star
49

AspirePulumi

A demo showing pulumi and aspire
C#
34
star
50

HotReload

Another attempt at hotreloading
C#
33
star
51

Core3HiddenGems

Demos for the NDC Oslo 2019 Talk
32
star
52

Sockets

31
star
53

DocsStaging

30
star
54

SignalR.Lite

A lightweight version of SignalR
JavaScript
30
star
55

FasterActions

exploring faster code generation techniques that take advantage of the JIT's de-virtualization and in-lining
C#
29
star
56

StreamingSample

A sample doing bidirectional streaming with ASP.NET Core and HTTP client
C#
27
star
57

SignalR.Orleans

SignalR orleans backplane
C#
27
star
58

BlazorBlog

C#
27
star
59

NdcLondon2018

C#
25
star
60

QueueDown

C#
25
star
61

OtlpDemo

Demo of .NET an otlp
C#
24
star
62

NdcLondon2020

Demos for NDC London 2020
HTML
22
star
63

AspireWithRedis

A simple hello world aspire redis project
C#
21
star
64

AsyncIO

Helper library for doing async io in .net
C#
19
star
65

AspNetCoreCsproj

ASP.NET Core project in a classic .NET Framework Console Library
C#
17
star
66

SignalRAsyncPatterns

JavaScript
17
star
67

SourceGeneratorPlayground

A playground for source generation ideas for asp.net core
C#
17
star
68

vNextLanguageSupport

A project that has examples of how to support different languages in the vNext project system
C#
16
star
69

ServiceProviderFactorySample

C#
15
star
70

PluginSample

A sample showing plugin systems in .NET
C#
15
star
71

WebQWorker

C#
13
star
72

GenericHostPOC

WebHost POC for generic host
C#
12
star
73

HostingOptions

A sample repository showing hosting options for ASP.NET 5 projects
C#
12
star
74

NuGet.Build

Build script used by NuGet package restore.
12
star
75

DiagnosticListenerSample

A sample showing how to use DiagnosticListener to handle request events
C#
12
star
76

build2018talk

C#
11
star
77

DesignTimeHostDemo

Example of how to use the ASP.NET vNext design time host
C#
11
star
78

BasicKestrel

C#
10
star
79

PipelinesSample

C#
10
star
80

XmlSettings

A general purpose settings ini style file in xml format.
C#
10
star
81

ConfigSourceGenerator

C#
10
star
82

SignalR.Ninject

Ninject dependency resolver for SignalR
C#
10
star
83

nuget-stats

Statistics web app for the official NuGet gallery.
C#
8
star
84

ReleaseNotesMaker

Little tool to generate release notes for SignalR
C#
8
star
85

ODataNullPropagationVisitor

Fix for odata's aggressive null propagation logic
C#
8
star
86

AzureSignalRLightupPrototype

Prototype of new azure signalr startup experience with ASP.NET Core 3.0
C#
8
star
87

LinkedAspNetCoreApplication

C#
8
star
88

AspireEventHub

A sample showing event hubs and aspire
C#
8
star
89

MinimalDiagnosticsSDK

C#
7
star
90

SignalR.Fleck

JavaScript
7
star
91

ParsingTechniques

6
star
92

Oscon2016

C#
6
star
93

Tshtml

Ideas
C#
6
star
94

WorkerTemplate

C#
6
star
95

aspnet-buzz

A site written on ASP.NET 5 that displays a live feed of ASP.NET stuff
C#
6
star
96

NDCLondon2017

C#
6
star
97

SignalR.Relay

JavaScript
5
star
98

ReactivePlayground

Ideas around ASP.NET and Rx
C#
5
star
99

AuthCookieOptions

A sample showing how to configure cookie options from the DI container
C#
5
star
100

Coroutines

Messing around with async and scheduling
C#
5
star