Giter Site home page Giter Site logo

ksukaruji07 / authapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gramli/authapi

0.0 0.0 0.0 2.33 MB

An example of Authentication and Authorization in REST API using minimal API, Clean Architecture and design patterns. ASP.NET Core 7.0

License: MIT License

C# 100.00%

authapi's Introduction

Clean Architecture AuthApi

REST API demonstrates Authentication and Authorization with JWT token. Also shows how to use diferent Authorization policies in minimap api endpoints. All using Clean Architecture, minimal API and various of design patterns.

Example API allows to:

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

Endpoints use different types of authorization policies.

Menu

Get Started

Simply Run Auth.API and try it.

SwaggerUI

Motivation

Main motivation is to write practical example of Authorization and Authentication with minimal API and Clean Architecture.

Architecture

Projects folows Clean Architecture, but application layer is splitted to Core and Domain projects where Core project holds business rules and Domain project contains business entities.

As Minimal API allows to inject handlers into endpoint map methods, I decided to do not use MediatR, but still every endpoint has its own request and handler. Solution folows CQRS pattern, it means that handlers are separated by commands and queries, command handlers handle command requests and query handlers handle query requests. Also repositories (Repository pattern) are separated by command and queries.

Instead of throwing exceptions, project use Result pattern (using FluentResuls package) and for returning exact http response, every handler returns data wraped into HttpDataResponse object which contains also error messages collection and http response code.

Clean Architecture Layers

Solution contains four layers:

  • Auth.Api - entry point of the application, top layer
    • Endpoints
    • Middlewares (or Filters)
    • API Configuration
  • Auth.Infrastructure - layer for communication with external resources like database, cache, web service..
    • Repositories Implementation - access to database
    • External Services Proxies - proxy classes implementation - to obtain data from external web services
    • Infastructure Specific Services - services which are needed to interact with external libraries and frameworks
  • Auth.Core - business logic of the application
    • Request Handlers/Managers/.. - business implementation
    • Abstractions - besides abstractions for business logic are there abstractions for Infrastructure layer (Service, Repository, ..) to be able use them in this (core) layer
  • Auth.Domain - all what should be shared across all projects
    • DTOs
    • General Extensions

Horizontal Diagram (references)

Project Clean Architecture Diagram

Technologies

authapi's People

Contributors

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