ili*_*ian 8 cookies identityserver3
我有两个站点https://www.somesite.com(用户站点)和https://admin.anothersite.com(管理站点),我使用Identity Server 3进行访问控制,这是托管在https:// identity.somesite.com.
这些站点在身份服务器中配置为具有基于cookie的身份验证的同一客户端(不同的重定向URL).我想提供一种机制,管理站点的用户可以模拟用户站点的用户.
我已经看到我可以使用它发出cookie IssueLoginCookie,但是这个调用需要在身份服务器上,所以鉴于它在另一个域上,我无法看到它是如何工作的.
如何在身份服务器中支持用户模拟?
更新
我现在有管理站点生成一个这样的URL:
var url = 'http://localhost:61826/connect/authorize'
+ '?state=' + encodeURIComponent(((Date.now() + Math.random()) * Math.random()).toString().replace(".", ""))
+ '&nonce=' + encodeURIComponent(((Date.now() + Math.random()) * Math.random()).toString().replace(".", ""))
+ '&client_id=mvc'
+ '&redirect_uri=' + encodeURIComponent('http://localhost:64822/')
+ '&scope=' + encodeURIComponent('openid profile roles api1')
+ '&acr_values=' + encodeURIComponent('loginas:3230')
+ '&response_type=' + encodeURIComponent('id_token token')
+ '&prompt=login';
window.location.href = url;
Run Code Online (Sandbox Code Playgroud)
这允许我PreAuthenticateAsync在我的自定义上的方法中拾取登录事件IUserService并拦截登录.我目前的实施是:
public override async Task PreAuthenticateAsync(PreAuthenticationContext context)
{
if (context.SignInMessage.AcrValues.Any(acr => acr.StartsWith("loginas:")))
{
// Would need to also ensure that the user has the relevant persmissions to impersonate another user
var subjectId = _owinContext.Authentication.User.GetSubjectId();
var login = new AuthenticatedLogin
{
Name = "Impersonating For Fun",
Subject = "3230",
Claims = new List<Claim>
{
new Claim(Constants.ClaimTypes.Subject, "3230")
},
PersistentLogin = true,
IdentityProvider = Constants.BuiltInIdentityProvider,
AuthenticationMethod = "Cookies"
};
_owinContext.Environment.IssueLoginCookie(login);
var impersonationClaims = new List<Claim>
{
new Claim("AdminUserId", subjectId)
};
context.AuthenticateResult = new AuthenticateResult("3230", "Impersonating For Fun", impersonationClaims);
}
await Task.FromResult(0);
}
Run Code Online (Sandbox Code Playgroud)
用户未显示登录页面,并且已正确重定向到目标URL.但是,用户尚未更改为新用户,而是保留为原始用户.我错过了什么?
| 归档时间: |
|
| 查看次数: |
1012 次 |
| 最近记录: |