![](/img/trans.png)
[英]How to add a database retrieved value custom claim to JWT Token using ServiceStack
[英]How to add custom claim on Jwt Token based on user input?
我在向令牌中添加自定義聲明(租戶 ID)時遇到問題。 所以我的程序允許用戶使用租戶 ID 切換他們的工作區。 為此,我需要接收選定的租戶 ID 並在令牌內生成具有選定租戶 ID 的新令牌。
為了在登錄期間第一次生成令牌,我使用了這段代碼
var tokenResponse = await httpclient.RequestPasswordTokenAsync(new PasswordTokenRequest
{
Address = discoveryDocument.TokenEndpoint,
UserName = model.PhoneNumber,
Password = model.Password,
ClientId = Configuration["ClientInformation:ClientId"],
ClientSecret = Configuration["ClientInformation:ClientSecret"]
});
為了在他們登錄切換租戶后生成新令牌,我使用了刷新令牌。
var tokenResponse = await httpclient.RequestRefreshTokenAsync(new RefreshTokenRequest
{
Address = discoveryDocument.TokenEndpoint,
ClientId = Configuration["ClientInformation:ClientId"],
ClientSecret = Configuration["ClientInformation:ClientSecret"],
RefreshToken = model.RefreshToken
});
我已經看到配置文件服務如何使用 claimprincipal 接收數據,這就是我對如何在 claimprincipal 中插入新值感到困惑的地方
所以我的問題是如何將選定的租戶 ID 發送到配置文件服務?
我可以通過將用戶想要的租戶 ID 保存到數據庫中來做到這一點,並且我可以使用配置文件服務獲取租戶值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.