以编程方式登录到identityserver3

编程入门 行业动态 更新时间:2024-10-20 20:38:56
本文介绍了以编程方式登录到identityserver3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个第三方网站,该网站将我的网站嵌入其中,并且我的网站通过URL参数中的某些键来验证第三方.

I have 3rd party website which embeds my website inside it and my website validates the 3rd Party through some keys in the URL parameters.

第三方用户使用自己的身份验证模型登录(因为他们不与我的网站进行SSO或联合身份验证),并且我的网站与由IdentityServer3实现的我自己的身份提供程序兼容.

3rd party user login with their own authentication model (as they don't do SSO or federation with my website) and my website works with my own identity provider implemented by IdentityServer3.

问题是:我可以通过模仿的用户以编程方式登录到我的idp吗?好像第三方用户登录到他们的网站并访问我的嵌入式网站一样,那么我的网站会自动以假冒用户身份登录到我的idp,并且我的网站会显示给第三方用户?

The question is: Can I sign in with the impersonated user to my idp programmatically? As if 3rd party users login to their website, and accessing my embedded website, then my website automatically sign in to my idp with impersonated user and my website is shown to 3rd party user?

互动关系图

推荐答案

是的

var client = new HttpClient(); var dic = new Dictionary<string, string>(); dic.Add("client_id", "mvc"); dic.Add("client_secret", "secret"); dic.Add("grant_type", "password"); dic.Add("scope", "openid profile"); dic.Add("username", "yazan@catec.ae"); dic.Add("password", "P@ssword1"); var content = new FormUrlEncodedContent(dic); var msg = client.PostAsync("localhost:44383/identity/connect/token", content).Result.Content.ReadAsStringAsync().Result; string token = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(msg).access_token; var jwt = new JwtSecurityToken(token); var identity = new ClaimsIdentity("ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); foreach (var c in jwt.Claims) { var t = c.Type; var v = c.Value; identity.AddClaim(new Claim(t, v)); } IAuthenticationManager authenticationManager = HttpContext.GetOwinContext().Authentication; authenticationManager.SignOut("ApplicationCookie"); authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity); return Redirect("Index");

更多推荐

以编程方式登录到identityserver3

本文发布于:2023-11-17 02:02:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!