基本上我正在尝试获取当前访问Web Api的经过身份验证的用户(通过承载令牌)的当前声明集; 通过将当前主体注入到辅助类中,然后将其注入到注入ApiController的类中.
但是,返回的主体永远不是我想要的主体,因为它未经过身份验证且不包含任何声明.如果我在创建ApiController之后逐步执行它的构造函数,则正确设置本地ApiController.User主体值.
以下是我创建并链接到下面的示例解决方案的一些代码...
集装箱登记:
namespace PrincipalInjector
{
using System.Security.Principal;
using System.Threading;
using System.Web;
using System.Web.Http;
using SimpleInjector;
using SimpleInjector.Integration.WebApi;
public static class ContainerConfig
{
public static void Register(HttpConfiguration config)
{
Container container = new Container();
InitializeContainer(container);
container.RegisterWebApiControllers(config);
container.Verify();
config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
}
private static void InitializeContainer(Container container)
{
container.RegisterWebApiRequest<IPrincipal>(() =>
HttpContext.Current.User != null ? HttpContext.Current.User : Thread.CurrentPrincipal);
}
}
}
Run Code Online (Sandbox Code Playgroud)
样品控制器:
namespace PrincipalInjector.Controllers
{
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Security.Principal;
using System.Web.Http;
public class DefaultController …
Run Code Online (Sandbox Code Playgroud) 例如,我看到很多人使用“as”作为 OAuth 上返回项目的前缀
as:client_id
Run Code Online (Sandbox Code Playgroud)
谁能告诉我这有什么意义?
我在 OAuth 规范中没有看到它
谢谢
我试图了解使用 WCF、Claims 和 ADFS 3.0 开发框架需要什么。内部用户将根据 Active Directory 进行身份验证,外部用户将根据 SQL Server 表进行身份验证,并且授权存储在实现组和权限的数据库表中。我正在使用 WCF 而不是 Web Api 或 OWIN 创建 API。
我对使用 Identity Server 或 3rd 方产品不感兴趣,我只想知道如何创建自定义安全令牌服务以从我的成员资格表中读取并通过我的组和权限表设置声明。
我找不到任何有关此的信息。Visual Studio 2015 中没有身份和访问控制,似乎没有使用 WCF,只使用 Web Api、OWIN 和 MVC?
我在构建时不断收到此错误:
无法识别的配置节system.identityModel
我在配置中添加了以下内容:
<system.identityModel>
<identityConfiguration>
<audienceUris>
<add value="TEST"/>
</audienceUris>
<issuerNameRegistry type="System.IdentityModel.Tokens.ConfigurationBasedIssuerNameRegistry, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<trustedIssuers>
<add thumbprint="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234" name="YourSTSName"/>
</trustedIssuers>
</issuerNameRegistry>
<certificateValidation certificateValidationMode="None"/>
</identityConfiguration>
</system.identityModel>
Run Code Online (Sandbox Code Playgroud)
我正在使用.Net 4.6
我正在尝试使用 ASP.NET Core 1.0 中的 Facebook 身份验证中间件检索用户个人资料图片。我设法添加了这些配置以使用户图片可用
app.UseFacebookAuthentication(new FacebookOptions()
{
AppId = Configuration["Authentication:Facebook:AppId"],
AppSecret = Configuration["Authentication:Facebook:AppSecret"],
Scope = { "public_profile" },
Fields = { "picture" }
});
Run Code Online (Sandbox Code Playgroud)
并检索数据
var email = info.Principal.FindFirstValue(ClaimTypes.Email);
Run Code Online (Sandbox Code Playgroud)
和
var userName = info.Principal.FindFirstValue(ClaimTypes.GivenName);
Run Code Online (Sandbox Code Playgroud)
但是我现在如何检索用户图片,因为它没有声明类型?
我想在一个新项目中使用IdentityServer4.我在PluralSight视频"了解ASP.NET核心安全性"中看到,IdentityServer4可以与基于声明的安全性一起使用,以保护Web API.我已将IdentityServer4设置为单独的项目/解决方案.
我还看到您可以添加IProfileService以向IdentityServer4返回的令牌添加自定义声明.
一个计划是向用户添加新的声明,以授予他们访问api的不同部分的权限.但是,我无法弄清楚如何从api项目管理IdentityServer上的用户声明.我假设我应该调用IdentotyServer4来添加和删除用户声明?
此外,这是一个很好的方法,因为我不确定允许客户端为IdentityServer内部安全目的添加声明是否合理 - 并且可能导致冲突(例如,多个客户端使用'role'声明值'admin ").也许我应该在api项目中本地处理安全性,然后只使用'sub'声明来查找它们?
有没有人有这个好方法?
谢谢
authorization claims asp.net-web-api asp.net-core identityserver4
OASIS拥有http://schemas.xmlsoap.org/ws/2005/05/identity命名空间,但是我找不到在任何地方定义“名称”声明类型。还有其他声明,例如“名字”,“姓氏”,“电子邮件地址”等,但没有仅指“名称”的声明。
是否有定义此声明类型的权威位置?我有兴趣了解此声明的正确用法。
在 Intranet Web 应用程序中使用 Windows 身份验证我想实现以下目标:
在我寻找答案时,建议我需要添加ClaimsTransformation
到我的应用程序中:
使用 .Net Core 中的 Windows Authenticated 应用程序从 SQL 填充自定义声明
虽然我不完全理解解决方案以及为什么ClaimsTransformation
每个请求都会发生,所以我正在寻找以下问题的答案:
ClaimsTransformation
工作?ClaimsTransformation
仅使用 Windows 身份验证或基于表单的身份验证在每个请求上发生?我有一种方法可以在我们的应用程序中更新用户声明。
我以管理员用户身份登录,可以编辑其他用户。
我正在尝试删除一位用户的现有声明并分配新的声明。
结果UserManger
是使用I删除声明时ConcurrencyFailure
。(有时它可以工作,但大多数时候它会返回失败错误。)
代码:“并发失败”
描述:“乐观并发失败,对象已被修改。”
方法:
public async Task<bool> AssignClaimsToUser(string id, List<string> newClaims)
{
bool success = false;
ApplicationUser user = await _userManager.FindByIdAsync(id);
List<Claim> userClaims = new List<Claim>();
// Remove existing claims
IList<Claim> existingClaims = await _userManager.GetClaimsAsync(user);
var removal = await _userManager.RemoveClaimsAsync(user, existingClaims); // This fail
if (removal.Succeeded)
{
success = true;
// Add new claims
foreach (string policy in newClaims)
{
userClaims.Add(new Claim(policy, string.Empty, ClaimValueTypes.String));
}
await _userManager.AddClaimsAsync(user, userClaims);
}
return success;
}
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况以及如何解决此问题? …
claims-based-identity claims asp.net-identity asp.net-core asp.net-core-1.0
以下是我的用例:我需要向访问令牌添加声明,以便我可以在对我的资源进行策略评估期间使用它。我的策略是基于 javascript 的策略,它只能访问登录用户的保留和自定义属性。我使用以下 api 来推送声明:
curl -X POST \
http://localhost:8082/auth/realms/cms-non-prod/protocol/openid-connect/token \
-H 'Authorization: Bearer eyJhbGciOiJSXXXXXXXXXXXXXXXX' \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Postman-Token: ac020c2b-9efb-4817-81ea-61895c8775a7' \
-d 'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Auma-ticket&claim_token=ewoiaW5zdGl0dXRpb25JZCI6WyJEQ0IiXQp9& claim_token_format=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt&client_id=indra-bff \
&client_Secret=5760582d-74ff-496c-a6c2-2530ddde6408&audience=indra-bff'
Run Code Online (Sandbox Code Playgroud)
它添加了声明,但它添加到授权--> 权限--> 资源。如果我有基于 JS 的政策,我该如何阅读。任何有关此的指示都会有所帮助。下面是我点击上面的 url 时得到的令牌:
{
"jti": "4c00f1a4-8038-4c45-820d-23a9c9ab6d42",
"exp": 1580733917,
"nbf": 0,
"iat": 1580730317,
"iss": "http://localhost:8082/auth/realms/cms-non-prod",
"aud": "indra-bff",
"sub": "9ab2fc80-3a5c-426d-ae78-56de01d214df",
"typ": "Bearer",
"azp": "indra-bff",
"auth_time": 0,
"session_state": "2ab35757-d09d-4d52-946b-f519a1338abf",
"acr": "1",
"realm_access": {
"roles": [
"PR_DCB_RECON_ASSOCIATE",
"PR_YBL_RECON_ASSOCIATE",
"offline_access",
"uma_authorization",
"PR_DCB_RECON_MGR"
]
},
"resource_access": {
"indra-bff": { …
Run Code Online (Sandbox Code Playgroud)