Eshoponcontainers: Basket.API project failed to use ByPassAuthMiddleware

Created on 20 Oct 2020  ยท  13Comments  ยท  Source: dotnet-architecture/eShopOnContainers

If the authentication center identity.API is not enabled,
when using the manual default user test, the Claim is reported as an error.
ๅ›พ็‰‡

Because when we add a test user in the middleware(file : /src/Services/Basket/Basket.API/Infrastructure/Middlewares/ByPassAuthMiddleware.cs), the claim Type of the user Name is 'name':

new Claim("name", "Test user"),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname","User"),

But in BasketController CheckoutAsync method, using ClaimType is (http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name),

var userName = this.HttpContext.User.FindFirst(x => x.Type == ClaimTypes.Name).Value;

the two do not match.

bug

All 13 comments

On the other hand,
I think currentUserId should be assigned to a claims type named sub,
in which case, via /noauth?userid=xxx, which matches directly with the buyerId correspondence.

new Claim("sub", "1234"),
new Claim("sub", currentUserId),// <-- note this

Could you please reply? Thank you. Do I need to submit a PR?

Hi @anjoy8, thank you for reaching out.

Sorry couldn't get a chance to look into this. Will test it out and update you soon.

Hi @anjoy8,

I have spent sometime to look into this issue and tried to reproduce it at my end but unfortunately to do so.
Could you please share more information on the details steps you have followed at your end on using ByPassAuthMiddleware ?

Please note, we have known issue on OrderingScenarios.Cancel_basket_and_check_order_status_cancelled where similar NullReferenceException exception can be seen due to missing claim type to the Invoke method of FunctionalTests.Middleware.AutoAuthorizeMiddleware. By "manual default user test" did you try to refer the similar things ?

Thank you

The steps are as follows:

1. Download the source code for the Dev branch

ๅ›พ็‰‡

2. The basket.API project starts by default

ๅ›พ็‰‡

3. Configure EventBus and Redis ConnectionString and set UseLoadTest to true

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Microsoft": "Warning",
        "Microsoft.eShopOnContainers": "Debug",
        "System": "Warning"
      }
    }
  },
  "IdentityUrlExternal": "http://localhost:5105",
  "IdentityUrl": "http://localhost:5105",
  "ConnectionString": "xxx.25.251.xx,password=xxxx!",
  "AzureServiceBusEnabled": false,
  "EventBusConnection": "xxx.25.251.xx",
  "EventBusUserName": "xxx",
  "EventBusPassword": "xxxx!",
  "UseLoadTest": true

}

4. Start Kestrel mode

ๅ›พ็‰‡

5. Configure test user's userid = '123456798'

https://localhost:5103/noauth?userid=123456798
ๅ›พ็‰‡

6. Add a shopping cart

ๅ›พ็‰‡

7, Checkout user '123456798' shopping cart

{
  "city": "string",
  "street": "string",
  "state": "string",
  "country": "string",
  "zipCode": "string",
  "cardNumber": "string",
  "cardHolderName": "string",
  "cardExpiration": "2020-10-30T02:47:02.882Z",
  "cardSecurityNumber": "string",
  "cardTypeId": 1,
  "buyer": "123456798",
  "requestId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}

8. An exception error occurred

ๅ›พ็‰‡

ๅ›พ็‰‡

Hi @anjoy8 , thank you for providing this detailed information. Will test at my end and update you.

Hi @anjoy8 , thank you for providing this detailed information. Will test at my end and update you.

Hi @anjoy8, thank you for providing the details. I have reviewed that code and details at my end.
Yes, you are right that's a bug. And that's because of the wrong value of the name and sub claim which subsequently gets set in line 63: and line 68: in ByPassAuthMiddleware. And because of that method Task<ActionResult> CheckoutAsync in BasketController class throws _identityService.GetUserIdentity() gives you back the wrong userId and Null refernce exceptions.

Would you like to submit a PR with the changes in ByPassAuthMiddleware ?

Thank you.

Of course! I am willing to do it. I have submitted PR:https://github.com/dotnet-architecture/eShopOnContainers/pull/1508

In addition, I am now making some video about this architecture and promoting it in the community. I also really want to participate in the development and maintenance work. I don't know if it is ok.
(https://www.bilibili.com/video/BV1nT4y1L7vd)

Of course! I am willing to do it. I have submitted PR:#1508

In addition, I am now making some video about this architecture and promoting it in the community. I also really want to participate in the development and maintenance work. I don't know if it is ok.
(https://www.bilibili.com/video/BV1nT4y1L7vd)

Hi @anjoy8, thank you for the PR.

Great to see your video and different contribution. ๐Ÿ‘
Please note, your contribution is important and valuable to us and for the community.

You can look into the list of open issues and try to fix whichever is possible. Items marked as help wanted could be a good place to start. I will also try to ping you in different PRs for suggestions or validations.
Please feel free to share your thoughts, ideas and feedback.

Thanks again !

Ok!
I love this architecture and will try to fix some open issues

Hello @sughosneo @anjoy8,

I am a newbie in this repo, I'd like to contribute to this project, is there a bug list from easy to hard for me to get familiar with project?

Thanks,
Thanh

Hello @sughosneo @anjoy8,

I am a newbie in this repo, I'd like to contribute to this project, is there a bug list from easy to hard for me to get familiar with project?

Thanks,
Thanh

@thanhauco Currently there is no list, but you can modify the bug from the Issue list

Hello @sughosneo @anjoy8,
I am a newbie in this repo, I'd like to contribute to this project, is there a bug list from easy to hard for me to get familiar with project?
Thanks,
Thanh

@thanhauco Currently there is no list, but you can modify the bug from the Issue list

Thanks @anjoy8 . That's correct.

Thank you for your interest @thanhauco . You could pick up any open item of your choice and submit a PR against that. We will be happy to review and merge the changes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrunoLopes picture BrunoLopes  ยท  4Comments

nxtx picture nxtx  ยท  4Comments

Dudelsb picture Dudelsb  ยท  3Comments

CESARDELATORRE picture CESARDELATORRE  ยท  5Comments

shubham2325 picture shubham2325  ยท  4Comments