Giter VIP home page Giter VIP logo

ivaylokenov / architecture-of-asp.net-core-microservices-applications Goto Github PK

View Code? Open in Web Editor NEW
290.0 18.0 41.0 3.79 MB

Architecture of ASP.NET Core Microservices Applications

Home Page: https://softuni.bg/trainings/2999/architecture-of-asp-dot-net-core-microservices-applications-june-2020

License: GNU General Public License v3.0

JavaScript 0.94% TypeScript 20.24% HTML 11.71% CSS 1.56% C# 65.19% Dockerfile 0.36% Shell 0.02%

architecture-of-asp.net-core-microservices-applications's Introduction

Architecture of ASP.NET Core Microservices Applications

This repository contains the demo source code from my SoftUni course about ASP.NET Core microservices architecture.

If you'd like to support me and my projects, please consider:

Additional resources:

architecture-of-asp.net-core-microservices-applications's People

Contributors

dependabot[bot] avatar ivaylokenov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

architecture-of-asp.net-core-microservices-applications's Issues

AddIdentity readds the CookieHandler as default Authentication

Affected Services

Identity

Issue description:

Since we are adding Identity after our infrastructure code (where we specify JWT as default authentication method), I belive identity overrides our defaults back to Cookie authentication.

Server/CarRentalSystem.Identity/Startup.cs
        public void ConfigureServices(IServiceCollection services)
            => services
                .AddWebService<IdentityDbContext>(this.Configuration)
                .AddUserStorage()
... // ommited 

This means that our Authorizer attribute in IdentityController, does not work.

Server/CarRentalSystem.Identity/Controllers/IdentityController.cs
... // ommited 
        [HttpPut]
        [Authorize]
        [Route(nameof(ChangePassword))]
... // ommited 

image

Debug log:

Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request starting HTTP/1.1 PUT http://localhost:5001/Identity/ChangePassword application/json 62
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 PUT http://localhost:5001/Identity/ChangePassword application/json 62
Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets: Debug: Connection id "0HM1AAAKJVIL1" sending FIN because: "The client closed the connection."
Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id "0HM1AAAKJVIL1" disconnecting.
dbug: Microsoft.AspNetCore.Server.Kestrel[10]
      Connection id "0HM1AAAKJVIL1" disconnecting.
Microsoft.AspNetCore.Server.Kestrel: Debug: Connection id "0HM1AAAKJVIL1" stopped.
dbug: Microsoft.AspNetCore.Server.Kestrel[2]
      Connection id "0HM1AAAKJVIL1" stopped.
dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1001]
      1 candidate(s) found for the request path '/Identity/ChangePassword'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: 1 candidate(s) found for the request path '/Identity/ChangePassword'
dbug: Microsoft.AspNetCore.Routing.Matching.DfaMatcher[1005]
      Endpoint 'MU.Identity.Controllers.IdentityController.ChangePassword (MU.Identity)' with route pattern 'Identity/ChangePassword' is valid for the request path '/Identity/ChangePassword'
Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint 'MU.Identity.Controllers.IdentityController.ChangePassword (MU.Identity)' with route pattern 'Identity/ChangePassword' is valid for the request path '/Identity/ChangePassword'
Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Debug: Request matched endpoint 'MU.Identity.Controllers.IdentityController.ChangePassword (MU.Identity)'
dbug: Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware[1]
      Request matched endpoint 'MU.Identity.Controllers.IdentityController.ChangePassword (MU.Identity)'
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler: Debug: AuthenticationScheme: Identity.Application was not authenticated.
dbug: Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler[9]
      AuthenticationScheme: Identity.Application was not authenticated.
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
      Authorization failed.

Possible solution

Explicitly specifying the Authentication seems to fix it, thought it is a bit ugly, any better ideas?

Server/CarRentalSystem.Identity/Controllers/IdentityController.cs
... // ommited 
        [HttpPut]
        [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
        [Route(nameof(ChangePassword))]
... // ommited 

CarAds Pagination is improperly calculated

Affected Services

Dealers

Issue description:

When loading all the Car listings we create a SearchCarAdsOutputModel, which contains the current number of listed cars, the current page number and all the possible pages numbers.

The problem comes from the fact that we do not return the all the possible pages, but rather the total number of CarAds

CarRentalSystem.Dealers/Controllers/CarAdsController.cs
//omitted
 [HttpGet]
        public async Task<ActionResult<SearchCarAdsOutputModel>> Search(
            [FromQuery] CarAdsQuery query)
        {
            var carAdListings = await this.carAds.GetListings(query);

            var totalPages = await this.carAds.Total(query); // this is the issue here

            return new SearchCarAdsOutputModel(carAdListings, query.Page, totalPages);
        }
//omitted

CarRentalSystem.Dealers/Services/CarAds/CarAdService.cs
//omitted
public async Task<int> Total(CarAdsQuery query)
            => await this
                .GetCarAdsQuery(query)
                .CountAsync();

//omitted

This would lead to improper JSON as follows (this is mostly visible when you have a low number of car ads)

{
    "carAds": [
      // 3 carAds omitted
    ],
    "page": 1,
    "totalPages": 3
}

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.