繁花如伊
Idsv4是不关心客户端是谁的,我有一些想法,不知道是不是你需要的。首先在Core的IdentityServer4上自定义登录地址。services.AddIdentityServer(options =>
{ // 忽略
options.UserInteraction.LoginUrl = Configuration["ApplicationDTO:LoginUrl"]; // 假设是/users/signIn
options.UserInteraction.LogoutUrl = Configuration["ApplicationDTO:LogoutUrl"]; /
})新建一个UsersControllers.添加signIn的Action.[HttpGet]
[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)] public async Task<IActionResult> SignIn(string returnUrl) { //通过验证后即清除cookies
await HttpContext.SignOutAsync("Cookies"); #region Issued Cookie
List<Claim> source = new List<Claim>()
{ new Claim("sub",new Guid().ToString()), new Claim("name",User.Identity.Name), new Claim("idp", "xxxxx"), new Claim("role","Custom"), new Claim("auth_time", DateTimeOffset.Now.ToEpochTime().ToString(),"http://www.w3.org/2001/XMLSchema#integer")
};
source.Add(new Claim("amr", "authorization_code")); var identity = new ClaimsIdentity(source.Distinct<Claim>((IEqualityComparer<Claim>)new ClaimComparer()), "IdentityServer4", "name", "role"); var claimsPrincipal = new ClaimsPrincipal(identity); await HttpContext.SignInAsync(IdentityServerConstants.DefaultCookieAuthenticationScheme, claimsPrincipal, new AuthenticationProperties
{
IsPersistent = true,
ExpiresUtc = DateTimeOffset.Now.Add(TimeSpan.FromMinutes(43200))
}); #endregion
return Redirect(returnUrl);
}Authorize需要您在startup自己定义登录地址。那么流程就是如下这样的1.在浏览器访问idsv4服务端https://Coreidsv4/connect/authorize?......,会跳转到/users/login通过Authorize验证用户是否登录,如果未登录就通过Authorization配置的登录地址去登录。登录成功重定向回来。可以在users/login中填写自己要信息。继续下去,通过url获取授权码 code。然后再去拿code去换取token.注意参数填写正确。