{"id":25522212,"url":"https://github.com/dotnet-labs/jwtauthdemo","last_synced_at":"2025-04-05T10:08:56.706Z","repository":{"id":46215882,"uuid":"280456019","full_name":"dotnet-labs/JwtAuthDemo","owner":"dotnet-labs","description":"ASP.NET Core + Angular JWT auth demo; integration tests; login, logout, refresh token, impersonation, authentication, authorization; run on Docker Compose.","archived":false,"fork":false,"pushed_at":"2023-12-18T14:52:35.000Z","size":977,"stargazers_count":410,"open_issues_count":0,"forks_count":143,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-03-29T09:09:26.852Z","etag":null,"topics":["angular","api","asp-net-core","aspnetcore","authentication","authorization","docker","docker-compose","impersonation","integration-testing","json-web-token","jwt","jwt-auth","jwt-token","login","logout","refresh-token"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dotnet-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"changhuixu","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-07-17T15:10:51.000Z","updated_at":"2025-03-05T18:05:28.000Z","dependencies_parsed_at":"2025-02-26T19:21:35.668Z","dependency_job_id":null,"html_url":"https://github.com/dotnet-labs/JwtAuthDemo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-labs%2FJwtAuthDemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-labs%2FJwtAuthDemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-labs%2FJwtAuthDemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dotnet-labs%2FJwtAuthDemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dotnet-labs","download_url":"https://codeload.github.com/dotnet-labs/JwtAuthDemo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318744,"owners_count":20919484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","api","asp-net-core","aspnetcore","authentication","authorization","docker","docker-compose","impersonation","integration-testing","json-web-token","jwt","jwt-auth","jwt-token","login","logout","refresh-token"],"created_at":"2025-02-19T18:18:44.733Z","updated_at":"2025-04-05T10:08:56.687Z","avatar_url":"https://github.com/dotnet-labs.png","language":"C#","funding_links":["https://ko-fi.com/changhuixu","https://ko-fi.com/changhuixu'"],"categories":[],"sub_categories":[],"readme":"# JWT Auth Demo (Angular + ASP.NET Core / ASP.NET 8)\n\n\u003ca href='https://ko-fi.com/changhuixu' target='_blank'\u003e\u003cimg height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi3.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /\u003e\u003c/a\u003e\n\nThis 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.\n\n## Medium Articles\n\n1. [JWT Auth in ASP.NET Core](https://codeburst.io/jwt-auth-in-asp-net-core-148fb72bed03)\n\n   In this article, I will show you how to implement an ASP.NET Core web API application using JWT authentication and authorization.\n\n1. [JWT Authentication in Angular](https://codeburst.io/jwt-authentication-in-angular-48cfa882832c)\n\n   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.\n\n## Demo\n\n![jwt demo](./jwt-angular-app.gif)\n\n## Solution Structure\n\nThis 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.\n\n- `angular`\n  The SPA is served using NGINX on Docker. The application demonstrates JWT authorization in the front-end.\n- `webapi`\n  The ASP.NET Core web API app is served by Kestrel on Docker. This app has implemented HTTPS support.\n\n## Usage\n\nThe 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.\n\n```bash\ndocker-compose up --build --remove-orphans\n```\n\nThen visit [http://localhost:8080](http://localhost:8080) for the app, and [https://localhost:5001](https://localhost:5001) for Swagger document for the web API project.\n\n**NOTE:** You can also move the folders around to consolidate the solution as one ASP.NET Core web app using the SPA service.\n\n## Screenshots\n\n- **Front-end** ([http://localhost:8080](http://localhost:8080))\n\n  ![angular app](./localhost_8080.png)\n\n- **Back-end** ([https://localhost:5001](https://localhost:5001))\n\n  ![web api](./localhost_5001.png)\n\n## License\n\nFeel free to use the code in this repository as it is under MIT license.\n\n\u003ca href='https://ko-fi.com/changhuixu' target='_blank'\u003e\u003cimg height='36' style='border:0px;height:36px;' src='https://cdn.ko-fi.com/cdn/kofi3.png?v=2' border='0' alt='Buy Me a Coffee at ko-fi.com' /\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnet-labs%2Fjwtauthdemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdotnet-labs%2Fjwtauthdemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdotnet-labs%2Fjwtauthdemo/lists"}