我有一个身份服务器实现,正在测试和生产中的许多应用程序中使用。我目前正在开发一项新功能,使用身份服务器的客户端应用程序可以执行Azure服务管理REST api调用。为此,它需要一个令牌。我可以生成此令牌,存储它,甚至可以在身份服务器的AccountController
中访问它。
我的问题是弄清楚如何将此信息发送给客户。我不认为此令牌属于用户的声明。所以我尝试将它作为AuthenticationProperties
的一部分添加为令牌,但我似乎无法在客户端中访问它。我应该将它存储在像这样的会话中吗SO用户link?这个问题有一个答案,但这似乎不对(我甚至出于绝望而尝试过它!)
生成令牌
var resource = "https://management.azure.com/";
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
Events = new OpenIdConnectEvents
{
OnAuthorizationCodeReceived = async context =>
{
// Acquire the token for the resource and save it
}
}
}
在AccountController
public async Task<IActionResult> ExternalLoginCallback(string returnUrl)
{
string resource = "https://management.azure.com/";
// snip
result = await authContext.AcquireTokenSilentAsync(resource, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
// snip
AuthenticationProperties props = null;
var tokens = new List<AuthenticationToken>();
var id_token = info.Properties.GetTokenValue("id_token");
if (id_token != null)
{
tokens.Add(new AuthenticationToken { Name = "id_token", Value = id_token });
}
if (result != null)
{
tokens.Add(new AuthenticationToken { Name = "management_token", Value = result.AccessToken });
}
if (tokens.Any())
{
props = new AuthenticationProperties();
props.StoreTokens(tokens);
}
// snip
// Can I access these "props" on the client? I even tried adding it to `Items`, no luck.
await HttpContext.Authentication.SignInAsync(user.UserId, user.DisplayName, provider, props, additionalClaims.ToArray());
}
所以,我的问题是,这是正确的方法吗?如果是这样,我如何访问身份验证属性集?或者我应该尝试在Session
中保存吗?如果是这样,我如何将其存储在客户的会话中?
任何指针都会有所帮助。谢谢!