tsc*_*ege 4 c# saml-2.0 owin kentor-authservices
我正在评估Kentor auth服务(它的OWIN版本)以使用SAML对用户进行身份验证.现在我想对该服务另外提出索赔.与那里的样本一起,我能够将请求发送到服务并进行调试.
我做了一个自定义声明的身份验证管理器,在那里我可以看到另外的声明到达auth服务.但是后来(在肯德尔的例子中有一个查看主页/索引列出所有索赔)这个声明不再可用.有谁知道我做错了什么?
非常感谢!
将AuthServices(或任何外部登录)与ASP.NET Identity一起使用时,传入的声明仅用于在数据库中查找ASP.NET Identity用户.然后完全丢弃传入的用户,并加载和使用来自ASP.NET Identity的用户
在默认的MVC5模板中,完成从外部标识到ASP.NET标识的切换AccountController.ExternalLoginCallback().要保留传入的信息,您必须调整此方法.有两种选择.
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);
}
Run Code Online (Sandbox Code Playgroud)
将内容复制SignInAsync()到您的ExternalLoginCallback()方法.将调用解压缩到user.GenerateUserIdentityAsync()to a separate line and. Add claims before callingSignInAsync()`
// 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);
}
Run Code Online (Sandbox Code Playgroud)
也可以在没有ASP.NET标识的情况下使用外部登录.如果您只使用Idp中的身份而没有其他登录方法,则可能更容易使用.