• Stars
    star
    2,600
  • Rank 17,065 (Top 0.4 %)
  • Language
    C#
  • License
    MIT License
  • Created about 3 years ago
  • Updated 3 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,249
star
2

DotNetCodingPatterns

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

Todos

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

BedrockFramework

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

Micronetes

Micronetes is a local orchestrator inspired by kubernetes that makes developing and testing microservices and distributed applications easier.
C#
775
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#
240
star
9

TriviaR

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

Roslyn.Reflection

Reflection APIs over roslyn symbol APIs
C#
182
star
11

QueryInterceptor

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

CommandAndControl

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

uController

A source generator for minimal APIs
C#
158
star
14

IdentityEndpointsSample

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

YarpTunnelDemo

YARP demo showing how tunneling can be implemented over websockets
C#
147
star
16

IISCrossover

A prototype running ASP.NET and ASP.NET Core in the same IIS pipeline
C#
135
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#
118
star
20

eStoreLite

Simple eStore frontend backend application using ASP.NET Core
C#
105
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

94
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

HelloWorldVNext

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

SmartLoadBalancer

Sticky sessions without sticky sessions
C#
74
star
29

Scheduling

Experimenting with schedulers
C#
68
star
30

Jabbot

Bot API for JabbR
C#
67
star
31

CacheR

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

UT3

C#
60
star
33

CommunityStandUpNet5

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

AspNetCoreRecipes

Recipes for common ASP.NET Core patterns
50
star
35

OwinHttpClient

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

AspNetCoreOwinSample

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

MessengR

One on one messenger app using SignalR
JavaScript
45
star
38

Streamer

JSON RPC over any bidirectional stream
C#
43
star
39

RestSample

C#
42
star
40

TcpProxy

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

AspireYarp

Yarp resource for Aspire.Hosting
C#
38
star
42

ServerStack

C#
36
star
43

Orleans.PubSub

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

HotReload

Another attempt at hotreloading
C#
33
star
45

DocsStaging

32
star
46

gRPCSamples

C#
32
star
47

Core3HiddenGems

Demos for the NDC Oslo 2019 Talk
32
star
48

Sockets

31
star
49

SignalR.Lite

A lightweight version of SignalR
JavaScript
30
star
50

FasterActions

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

StreamingSample

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

SignalR.Orleans

SignalR orleans backplane
C#
27
star
53

AspirePulumi

A demo showing pulumi and aspire
C#
26
star
54

NdcLondon2018

C#
25
star
55

QueueDown

C#
25
star
56

BlazorBlog

C#
25
star
57

OtlpDemo

Demo of .NET an otlp
C#
24
star
58

NdcLondon2020

Demos for NDC London 2020
HTML
22
star
59

AsyncIO

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

AspNetCoreCsproj

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

SignalRAsyncPatterns

JavaScript
17
star
62

vNextLanguageSupport

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

SourceGeneratorPlayground

A playground for source generation ideas for asp.net core
C#
16
star
64

ServiceProviderFactorySample

C#
15
star
65

PluginSample

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

WebQWorker

C#
12
star
67

GenericHostPOC

WebHost POC for generic host
C#
12
star
68

HostingOptions

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

NuGet.Build

Build script used by NuGet package restore.
12
star
70

DiagnosticListenerSample

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

build2018talk

C#
11
star
72

DesignTimeHostDemo

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

BasicKestrel

C#
10
star
74

PipelinesSample

C#
10
star
75

XmlSettings

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

ConfigSourceGenerator

C#
10
star
77

SignalR.Ninject

Ninject dependency resolver for SignalR
C#
10
star
78

nuget-stats

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

ReleaseNotesMaker

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

AzureSignalRLightupPrototype

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

LinkedAspNetCoreApplication

C#
8
star
82

ODataNullPropagationVisitor

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

AspireSwaggerUI

An aspire resource for showing swagger ui
C#
7
star
84

MinimalDiagnosticsSDK

C#
7
star
85

SignalR.Fleck

JavaScript
7
star
86

AspireEventHub

A sample showing event hubs and aspire
C#
7
star
87

ParsingTechniques

6
star
88

Oscon2016

C#
6
star
89

Tshtml

Ideas
C#
6
star
90

aspnet-buzz

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

WorkerTemplate

C#
6
star
92

NDCLondon2017

C#
6
star
93

NewId

A sequential id generator that works across nodes with no collisions
C#
6
star
94

SignalR.Relay

JavaScript
5
star
95

ReactivePlayground

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

AuthCookieOptions

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

Coroutines

Messing around with async and scheduling
C#
5
star
98

CompileModules

POC to show what you can do with ICompileModule
C#
4
star
99

Webstack

Building a webstack from scratch (Because I can)
C#
4
star
100

NodeBlog

JavaScript
3
star