带有身份服务器4的asp.net Web表单客户端 [英] asp.net web form client with identity server 4

查看:65
本文介绍了带有身份服务器4的asp.net Web表单客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由以下组成的asp.net解决方案

1). asp.net identity server rc 3
2). asp.net Core web api
3). asp.net webform ( not in asp.net core, client)

我没有看到身份服务器4和Web表单客户端的任何示例.您能否建议如何使用具有asp.net身份的身份服务器对Web表单用户进行身份验证,然后使用访问令牌调用api?

我看不到带有网络表单客户端示例

身份服务器3具有样本,但它正在启动

当我看到 mvc客户端对于身份服务器4,它在configure方法中具有所有设置,然后像解决方案

最新答案,但希望它对仍支持Web表单的人有所帮助.
将启动与Web窗体一起使用是没有问题的.唯一的限制是AuthorizeAttribute在那里没有地方,但是仍然没有问题,只需输入:

app.UseStageMarker(PipelineStage.Authenticate);

位于您

的底部

public void Configuration(IAppBuilder app)

OWIN启动中的方法.

示例启动实现
从我的github中获取.它可以与MVC,Web Forms一起使用,并且还可以从IdentityServer v.3的代码库中进行JWT验证,该代码库已升级为可以与最新的OWIN库一起编译.


如果我还有什么不清楚的地方,请随时在评论中提问.

I have a asp.net solution which consists of

1). asp.net identity server rc 3
2). asp.net Core web api
3). asp.net webform ( not in asp.net core, client)

I don't see any sample with identity server 4 and web form client. Can you please suggest how to authenticate web form user using identity server with asp.net identity and then call api with the access token ?

I don't see identity server 4 sample with web form client or sample

identity server 3 has a sample but it is doing everything in startup

When i see mvc client for identity server 4, it has all settings in configure method and then calls it like this

How will i apply Authorize attribute in webform so that i am redirected to identity server 4 for login and then after login when i call api like this:

how to change client for webform ?

 new Client()
                  {
                    ClientId = "mvcClient",
                    ClientName = "MVC Client",                    
                    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

                    ClientSecrets = new List<Secret>()
                    {
                        new Secret("secret".Sha256())
                    },

                    RequireConsent = false;

                    // where to redirect to after login
                    RedirectUris = { "http://localhost:5002/signin-oidc" },
                    // where to redirect to after logout
                    PostLogoutRedirectUris = { "http://localhost:5002" },

                    AllowedScopes =
                    {
                        StandardScopes.OpenId.Name,
                        StandardScopes.Profile.Name,
                        StandardScopes.OfflineAccess.Name,
                        StandardScopes.Roles.Name,
                        "API"
                    }
                }

new InMemoryUser()
            {
                Subject = "1",
                Username = "testuser",
                Password = "password",
                Claims = new List<Claim>()
                {
                    new Claim("name", "Alice"),
                    new Claim("Website", "http://alice.com"),
                     new Claim(JwtClaimTypes.Role, "admin")

                }
            }


 return new List<Scope>()
                {
                    StandardScopes.OpenId, // subject id
                    StandardScopes.Profile, // first name, last name
                    StandardScopes.OfflineAccess, 
                   StandardScopes.Roles,
                    new Scope()
                    {
                        Name = "API",
                        Description = "API desc",
                         Type = ScopeType.Resource,
                        Emphasize = true,
                        IncludeAllClaimsForUser = true,
                        Claims = new List<ScopeClaim>
                        {
                            new ScopeClaim(ClaimTypes.Name),      
                            new ScopeClaim(ClaimTypes.Role)
                        }
                    }
                };


 public void CallApiUsingClientCredentials()
                {
                    var tokenClient = new TokenClient("http://localhost:5000/connect/token", "mvc", "secret");
                    var tokenResponse = await tokenClient.RequestClientCredentialsAsync("api1");

                    var client = new HttpClient();
                    client.SetBearerToken(tokenResponse.AccessToken);
                    var content = await client.GetStringAsync("http://localhost:5001/identity");

                    var result = JArray.Parse(content).ToString();

                }

 [Authorize(Roles="admin)]
          [HttpGet]
           public IActionResult Get()
                    {
                        return new JsonResult(from c in User.Claims select new { c.Type, c.Value });
                }

解决方案

Late answer, but hopefully it helps someone, still supporting web forms.
There is no problem to use startup together with web forms. The only limitation is no place for AuthorizeAttribute there, but it's still not a problem, just put:

app.UseStageMarker(PipelineStage.Authenticate);

at the bottom of your

public void Configuration(IAppBuilder app)

method within OWIN Startup.

An example Startup implementation could be fetched from my github. It works with MVC, Web Forms and additionally brings JWT validation from IdentityServer v.3' codebase, upgraded to compile with the latest OWIN libraries.


If I still left anything unclear, don't hesitate to ask in the comments.

这篇关于带有身份服务器4的asp.net Web表单客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆