Skip to content

ASP.NET Core API with JWT authentication and authorization

Notifications You must be signed in to change notification settings

cthtrifork/TodoApi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b5195f8 · Nov 21, 2022
Nov 13, 2022
Nov 14, 2022
Nov 19, 2022
Nov 12, 2022
Nov 21, 2022
Nov 21, 2022
Nov 12, 2022
Mar 6, 2022
Nov 21, 2022
Mar 6, 2022
Nov 14, 2022

Repository files navigation

Todo REST API with ASP.NET Core

CI

Todo REST API samples using ASP.NET Core minimal APIs. It showcases:

  • Using EntityFramework and SQLite for data access
  • JWT authentication
  • OpenAPI support
  • Rate Limiting
  • Writing 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 and run dotnet ef database update to create the database.
  3. Learn more about dotnet-ef

Authentication

  1. Run dotnet user-jwts create to create a JWT token for your user and dotnet user-jwts create -n admin --role admin to create an admin user.
  2. You should be able to use these tokens to make authenticated requests to the endpoint.
  3. Learn more about user-jwts

Optional

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. Uncomment .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

Logs

  1. Uncomment .AddOtlpExporter below builder.Logging.AddOpenTelemetry, in the TodoApi/Extensions/OpenTelemetryExtensions.cs file
  2. Find a Vendor that supports OpenTelemetry-based logging.

Vendor support for OpenTelemetry-based logging is currently very limited.

About

ASP.NET Core API with JWT authentication and authorization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.6%
  • Shell 0.4%