如何将索赔(或一组索赔)添加到AppSettings文件中?
我有一个通常连接到身份验证服务的应用程序,该服务为当前用户提供身份。通常,当我旅行或通勤时,我没有互联网访问,需要在本地模式下工作。在此环境中,我想使用AppSettings文件将一组索赔进行用力编码,以便为当前的用户提供身份。
我遇到困难的 system.security.claims 结构。我正在使用此 POST <54645939“> /a>,但配置系统无法识别它。这是我试图从配置中读取的类的定义:
public class HttpHost
{
public Uri BaseAddress { get; set; }
[JsonConverter(typeof(ClaimConverter))]
public System.Security.Claims Claim { get; set; }
public string Identifier { get; set; }
public TimeSpan Timeout { get; set; }
}
这是实际数据:
"HttpHosts": [
{
"BaseAddress": "https://localhost/",
"Claim": {
"Issuer": "LOCAL AUTHORITY",
"OriginalIssuer": "LOCAL AUTHORITY",
"Type": "http://my.org/ws/2015/01/identity/claims/mytype",
"Value": "myvalue",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
},
"Identifier": "ThetaRex.OpenBook.Desktop.Common.OpenBookHost",
"Timeout": "00:01:23"
}],
如何获得配置系统来识别自定义类型转换器-SoiperConverter-,以便在与DI:
public HttpHost(IOptions<List<HttpHost>> options)
{
HttpHost httpHost = options.Value.Find(h => h.Identifier == typeof(T).FullName);
...
}
I have an application that is normally connected to an authentication service that provides an identity for the current user. Often, when I'm travelling or commuting, I don't have internet access and need to work in a local mode. In this environment, I want to hard-code a set of claims into the application using the appSettings file in order to give the current user an identity.
I'm having trouble deserializing the System.Security.Claims structure. I'm using the deserialization method found on this post, but the Configuration system isn't recognizing it. Here's the definition of the class I'm trying to read from the configuration:
public class HttpHost
{
public Uri BaseAddress { get; set; }
[JsonConverter(typeof(ClaimConverter))]
public System.Security.Claims Claim { get; set; }
public string Identifier { get; set; }
public TimeSpan Timeout { get; set; }
}
Here's the actual data:
"HttpHosts": [
{
"BaseAddress": "https://localhost/",
"Claim": {
"Issuer": "LOCAL AUTHORITY",
"OriginalIssuer": "LOCAL AUTHORITY",
"Type": "http://my.org/ws/2015/01/identity/claims/mytype",
"Value": "myvalue",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
},
"Identifier": "ThetaRex.OpenBook.Desktop.Common.OpenBookHost",
"Timeout": "00:01:23"
}],
How do I get the Configuration system to recognize the custom type converter - ClaimConverter - such that it will work when using it with DI:
public HttpHost(IOptions<List<HttpHost>> options)
{
HttpHost httpHost = options.Value.Find(h => h.Identifier == typeof(T).FullName);
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码在Visual Studio中进行了测试,如果您需要使用特殊的类索赔,则可以正常
更新
工作,可以使用映射器或手动将此索赔转换为您的类声明(也可以将此代码添加到Getter或Setter)
类
this code was tested in visual studio and working properly
UPDATE
if you need to use a special class Claims you can convert this claim to your class Claims using a mapper or manually ( you can add this code to getter or setter as well)
classes