简体   繁体   English

Kentor Auth服务 - 附加索赔

[英]Kentor Auth Services - Additional Claim

I'm evaluating the Kentor auth services (the OWIN version of it) to authenticate users using SAML. 我正在评估Kentor auth服务 (它的OWIN版本)以使用SAML对用户进行身份验证。 Now I would like to pass an additional claim to the service. 现在我想对该服务另外提出索赔。 Together with the samples there I was able to send the request to the service and debug it. 与那里的样本一起,我能够将请求发送到服务并进行调试。

I made a custom claimsAuthenticationManager and there I can see the additional claim arriving at the auth service. 我做了一个自定义声明的身份验证管理器,在那里我可以看到另外的声明到达auth服务。 But later on (in the Kendor examples there is a the view home/index listing all the claims) this claim is not available anymore. 但是后来(在肯德尔的例子中有一个查看主页/索引列出所有索赔)这个声明不再可用。 Does anyone have an idea what i'm doing wrong? 有谁知道我做错了什么?

Thanks a lot! 非常感谢!

When using AuthServices (or any external login) together with ASP.NET Identity, the incoming claims are only used for looking up the ASP.NET Identity user in the database. 将AuthServices(或任何外部登录)与ASP.NET Identity一起使用时,传入的声明仅用于在数据库中查找ASP.NET Identity用户。 Then incoming user is then discarded completely and the user from ASP.NET Identity is loaded and used 然后完全丢弃传入的用户,并加载和使用来自ASP.NET Identity的用户

In the default MVC5 template, the switch from the external identity to the ASP.NET Identity is done in AccountController.ExternalLoginCallback() . 在默认的MVC5模板中,从外部标识到ASP.NET标识的切换是在AccountController.ExternalLoginCallback() To keep the incoming information you have to adjust this method. 要保留传入的信息,您必须调整此方法。 There are two options. 有两种选择。

1. Update stored user in ExternalLoginCallback() 1.在ExternalLoginCallback()更新存储的用户

// Sign in the user with this external login provider if the user already has a login
var user = await UserManager.FindAsync(loginInfo.Login);
if (user != null)
{
  // Update user with info from external identity and save.
  user.GivenName = loginInfo.ExternalIdentity.FindFirst(ClaimTypes.GivenName).Value;
  await UserManager.UpdateAsync(user);

  await SignInAsync(user, isPersistent: false);
  return RedirectToLocal(returnUrl);
}

2. Use the incoming claims for current session only. 2.仅使用当前会话的传入声明。

Copy the contents of SignInAsync() to your ExternalLoginCallback() method. SignInAsync()的内容复制到ExternalLoginCallback()方法。 Extract the call to user.GenerateUserIdentityAsync() to a separate line and. Add claims before calling 将对user.GenerateUserIdentityAsync()的调用解压缩to a separate line and. Add claims before calling to a separate line and. Add claims before calling SignInAsync()` to a separate line and. Add claims before calling SignInAsync() to a separate line and. Add claims before calling

// Sign in the user with this external login provider if the user already has a login
var user = await UserManager.FindAsync(loginInfo.Login);
if (user != null)
{
  AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
  var identity = await user.GenerateUserIdentityAsync(UserManager);
  identity.AddClaim(loginInfo.ExternalIdentity.FindFirst(ClaimTypes.GivenName));
  AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent },
    identity);

  return RedirectToLocal(returnUrl);
}

Suggestion 建议

It is also possible to use external login without ASP.NET Identity . 也可以在没有ASP.NET标识的情况下使用外部登录 If you're only using identities from the Idp and no other login method, that is probably easier to work with. 如果您只使用Idp中的身份而没有其他登录方法,则可能更容易使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Kentor Auth Services中找不到实体ID为“ http://stubidp.kentor.se/Metadata”的IDp错误 - No Idp with entity id “http://stubidp.kentor.se/Metadata” found error in Kentor Auth Services 从 ADFS 声明授权 - Claim auth from ADFS 使用附加服务创建子 scope - Create child scope with additional services 如何在自定义声明中反序列化 JSON(来自 Auth0)? - How to deserialize JSON inside a custom claim (from Auth0)? 使用来自 Google auth (SPA) 的 IdentityServer 获取姓名和电子邮件声明 - Get name and email claim using IdentityServer from Google auth (SPA) .net核心3-b2c角色身份验证-声明注入不起作用 - .net core 3 - b2c roles auth - claim injection not working 使用 Firebase Auth 存储附加信息 - Using Firebase Auth to store additional information 在 WCF 数据服务中公开实体的其他属性 - Exposing additional properties on entities in WCF Data Services WCF RIA SERVICES AuthenticationDomainService 从用户 class 获取附加参数 - WCF RIA SERVICES AuthenticationDomainService get additional parameter from User class 使用Kentor.AuthServices.StubIdp作为生产IDP - Using Kentor.AuthServices.StubIdp as production IDP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM