Giter Site home page Giter Site logo

cuongdo926 / jwtauthdemo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnet-labs/jwtauthdemo

0.0 0.0 0.0 1.29 MB

ASP.NET Core + Angular JWT auth demo; integration tests; login, logout, refresh token, impersonation, authentication, authorization; run on Docker Compose.

License: MIT License

C# 66.69% TypeScript 25.56% CSS 2.60% HTML 3.81% Dockerfile 1.34%

jwtauthdemo's Introduction

JWT Auth Demo (Angular + ASP.NET Core / ASP.NET 5+)

Buy Me a Coffee at ko-fi.com

This repository demos an Angular SPA and an ASP.NET Core web API application using JWT auth, and an integration testing project for a set of actions including login, logout, refresh token, impersonation, authentication, and authorization.

Medium Articles

  1. JWT Auth in ASP.NET Core

    In this article, I will show you how to implement an ASP.NET Core web API application using JWT authentication and authorization.

  2. JWT Authentication in Angular

    In this article, we will build a simple app using Angular. We will implement an AuthService class to handle login, logout, and refresh token processes, as well as operations for localStorage key-value pairs. We will create a JwtInterceptor class to add JWT Bearer token to the HTTP request headers, and an UnauthorizedInterceptor class to redirect the user to the login page if an HTTP status code 401 is received. We will use an AuthGuard to prevent unauthenticated user from visiting the application pages.

Demo

jwt demo

Solution Structure

This repository includes two applications: an Angular SPA in the angular folder, and an ASP.NET Core web API app in the webapi folder. The SPA makes HTTP requests to the server side (the webapi app) using an API BaseURL https://localhost:5001. The API BaseURL is set in the environment.ts file and the environment.prod.ts file, which can be modified based on your situation.

  • angular The SPA is served using NGINX on Docker. The application demonstrates JWT authorization in the front-end.
  • webapi The ASP.NET Core web API app is served by Kestrel on Docker. This app has implemented HTTPS support.

Usage

The demo is configured to run by Docker Compose. The services are listed in the docker-compose.yml file. You can launch the demo by the following command.

docker-compose up --build --remove-orphans

Then visit http://localhost:8080 for the app, and https://localhost:5001 for Swagger document for the web API project.

NOTE: You can also move the folders around to consolidate the solution as one ASP.NET Core web app using the SPA service.

Screenshots

License

Feel free to use the code in this repository as it is under MIT license.

Buy Me a Coffee at ko-fi.com

jwtauthdemo's People

Contributors

changhuixu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.