Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An example of a full-stack application for Authentication and Authorization, build with ASP.NET Core 9.0 (Minimal API) and Angular 19.

License

NotificationsYou must be signed in to change notification settings

Gramli/AuthApi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clean Architecture AuthApi

.NET Build and TestAngular Build

This full-stack solution demonstrates user registration, login, and role-based access control using Angular and .NET. The backend showcasesAuthentication andAuthorization withJWT tokens, demonstrating the use of Authorization policies inminimal API endpoints and adding custom claims through middleware. These are all implemented following Clean Architecture and various design patterns. The frontend illustrates managing JWT tokens usingguards andinterceptors, with all components implemented asstandalone components andsignals.

Example API allows to:

  • register user
  • login user
  • change user role
  • get user and service info

Endpoints use different types of authorization policies.

Menu

Prerequisites

  • .NET SDK 9.0+
  • Angular CLI 19+
  • Node.js 20.11.1+

Installation

To install the project using Git Bash:

  1. Clone the repository:
    git clone https://github.com/Gramli/AuthApi.git
  2. Navigate to the project directory:
    cd AuthApi/src
  3. Install the backend dependencies:
    dotnet restore
  4. Navigate to the frontend directory and install dependencies:
    cd Auth.Frontendnpm install

Get Started

Run Solution

Expected IDE

  • Backend: Visual Studio 2019+ or JetBrains Rider 2024.2.7+
  • Frontend: Visual Studio Code 1.94.2+ or WebStorm 2024.2.4+
  1. Run Frontend

    1. Open theAuth.Frontend project folder:
      • In WebStorm, use the run or debug button to start the project.
      • In VS Code, run the project in the terminal using the commandng serve.
    2. In your browser, navigate tohttp://localhost:4200/.
  2. Run Backend

    1. Open theAuthSol.sln project in Rider or Visual Studio.
    2. Use the run button to start the backend project.
  3. Once both the frontend and backend are running, you’re all set to start using the app. Enjoy! :)

Test Using SwaggerUI

Select theAuth.API startup item in VS or Rider and try it.

SwaggerUI

Test Using .http file (VS2022)

  • Go to Tests/HttpDebugTests folder and opendebug-tests.http file in VS2022
  • Send Login request
  • Obtain jwtToken from response and use it in another requests in Authorization header

Motivation

The primary goal of this project is to create a practical example of authorization and authentication using Minimal API and Clean Architecture, while also enhancing my skills with Angular.

Backend Architecture

The backend followsClean Architecture, with the application layer split intoCore andDomain projects:

  • TheCore project contains business rules.
  • TheDomain project holds business entities.

Key Patterns and Decisions:

  • CQRS Pattern: Separates handlers into commands and queries, with repositories structured similarly.
  • No MediatR: Minimal API supports injecting handlers directly into endpoint map methods, eliminating the need forMediatR.
  • Result Pattern: Uses theResult pattern (viaFluentResults package) instead of throwing exceptions. Each handler returns anHttpDataResponse object containing data, error messages, and the HTTP response code.

Frontend Structure

The Angular frontend is organized into two main folders:

  • Core: Contains "feature" components (each with specific feature logic).
  • Shared: Stores common components, services, and extensions shared between feature components.

JWT Handling

This example demonstrates JWT token management on the client side. After obtaining the token from the API, it is stored in local storage via theJwtTokenService. TheAuthorizeGuard checks if the client already has a token to protect routes, andauthInterceptor automatically adds the token header to every request.

The project usesPrimeNG andPrimeFlex for styling and layout.

Technologies

About

An example of a full-stack application for Authentication and Authorization, build with ASP.NET Core 9.0 (Minimal API) and Angular 19.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp