Skip to content

Minimal ASP.NET Core JSON API. Data secured with json web tokens, JWT, and ASP.Net Core Identity membership system for login.

License

Notifications You must be signed in to change notification settings

soixantseize/aspnetcore-api-jwt-identity

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

BareMetalApi

Live example running on Heroku right now. Check out Heroku_Deploy branch for more details

WHAT

A lightweight and cross platform ASP.Net Core JSON API. CRUD to your PostgreSQL database out of the box thanks to Npgsql driver and EF Core dependency injection. Includes data migration script that runs on startup and seeds initial data. Get started right away!

Data security using tokens,JWT, and ASP.Net Core Identity, claims based authentication.

HOW

Disclaimer

This project borrows heavily from the following repos:

  1. ToDoApi blog post here

  2. ASPNETcoreAngularJWT

Prerequisites

  1. Install .NET Core (https://www.microsoft.com/net/core)
  2. Install PostgreSQL (https://www.postgresql.org/)
  3. Add an appsettings.json file to /src/BareMetalApi, which will define your db connection string.
    • {
      "ConnectionStrings": {
      "DefaultConnection": "User ID=postgres;Password=password;Host=localhost;Port=5432;Database=Blog;Pooling=true;"
      }
      }

To run application

  1. Download repository
  2. Open command prompt and navigate to /src/BareMetalApi
  3. Run command "dotnet restore"
    • Please create new issue if you are having trouble downloading dependencies
  4. Run command "dotnet run"
    • App will compile then run, wait for message Application started. Press Ctrl+C to shut down.
  5. First Register a User: Use Postman to send a POST request in order to register your first user.
    • POST http://localhost:5000/blog/account/register
      {"Email" : "YourName@ok.com", "PasswordHash" : "Abc!"}
  6. Get Security Token: Use Postman to login your user.
    • POST http://localhost:5000/blog/account/login
      Body
      x-www-form-urlencoded
      Email YourName@ok.com
      Password Abc123!
  7. Use your security tokens to send JSON GET, POST, PUT, and DELETE requests.
    • GET http://localhost:5000/blog/blogarticle
      Headers
      Authorization Bearer eyJhbGc...FULL TOKEN...RrXfOA
      {
      "Id": 1,
      "ArticleTitle": "How to Dabb",
      "ArticleContent": "First tuck you head down..."
      },
      {
      "Id": 2,
      "ArticleTitle": "How to Whip",
      "ArticleContent": "Rock back and forth..."
      },
      {
      "Id": 3,
      "ArticleTitle": "How to Nae Nae",
      "ArticleContent": "Add a connecting move..."
      },
      {
      "Id": 4,
      "ArticleTitle": "How to Dougie",
      "ArticleContent": "Pass your hand through..."
      },
      {
      "Id": 5,
      "ArticleTitle": "How to Wop",
      "ArticleContent": "Worm your upper body..."
      }

    • GET http://localhost:5000/blog/blogarticle/3
      Headers
      Authorization Bearer eyJhbGc...FULL TOKEN...RrXfOA
      {
      "Id": 3,
      "ArticleTitle": "How to Nae Nae",
      "ArticleContent": "Add a connecting move..."
      }

    • POST http://localhost:5000/blog/blogarticle
      {"ArticleTitle":"How to Running Man","ArticleContent":"Lift your right foot and..."}

    • PUT http://localhost:5000/blog/blogarticle/4
      {"ArticleTitle":"How to Moonwalk","ArticleContent":"Place one foot directly..."}

    • DELETE http://localhost:5000/blog/blogarticle/5

About

Minimal ASP.NET Core JSON API. Data secured with json web tokens, JWT, and ASP.Net Core Identity membership system for login.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%