JWT in Request Header is not the same in receiving .Net Core API

后端 未结 2 715
走了就别回头了
走了就别回头了 2021-01-20 17:02

When I make a request to my .Net Core 2 API from my Angular app the JWT is not the same as the one sent in the request header.

Startup.cs

         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 17:36

    Faced with same issue with sub changing to http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier, found answer in https://stackoverflow.com/a/62881110/11593686.

    But also, managed to solve the issue myself: I've checked that resulting token contains sub, so it gets transformed when reading/validating, so I just:

    var tokenHandler = new JwtSecurityTokenHandler();
    //otherwise `sub` (and some other claims) get changed to ClaimTypes.NameIdentifier
    tokenHandler.InboundClaimTypeMap = tokenHandler.OutboundClaimTypeMap;
    

    i.e. copied Outbound map to Inbound map, so they are equal.

提交回复
热议问题