我有帶有email宣告的Cognito id 令牌。
..........
"iat": 164456734,
"jti": "81ac2634-e241-444f-88cf-eabf454644",
"email": "[email protected]"
}
但是,在 c# 中,在 asp net core jwt 中間件身份驗證電子郵件宣告從emailtype轉換為http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress-ClaimTypes.Email之后。
但后來我手動讀取了令牌:
var token = new JwtSecurityTokenHandler().ReadJwtToken(jwtToken);
var claimsIdentity = new ClaimsIdentity(token.Claims);
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity)
宣告型別未轉換并保持不變email。
為什么在 asp net core 身份驗證宣告中轉換為http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress?
我claimsPrincipal可以在email不手動修改Claims串列的情況下手動創建此宣告轉換嗎?
uj5u.com熱心網友回復:
它實際上已經被理解為ClaimTypes.Email,但是這個屬性回傳的字串是http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress( source )。
除非特別這樣做,否則不會轉換標記,而是將其決議和理解為ClaimTypes.Email未修改的實際標記。
uj5u.com熱心網友回復:
因此,Microsoft 和 OpenIDConnect 對電子郵件宣告名稱應該是什么有不同的看法,要禁用此重新映射,您可以執行以下任一操作:
public void ConfigureServices(IServiceCollection services)
{
// By default, Microsoft has some legacy claim mapping that converts
// standard JWT claims into proprietary ones. This removes those mappings.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
JwtSecurityTokenHandler.DefaultOutboundClaimTypeMap.Clear();
// Or set this flag to false
.AddJwtBearer(opt =>
{
...
opt.MapInboundClaims = false;
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/419201.html
標籤:
上一篇:Azure函式iLoggerisEnabled未獲取host.json
下一篇:FLUTTER-在macbook上開發應用程式,您可以在iPhone和ANDROID(三星手機)手機上進行除錯嗎?
