带有身份服务器的asp.net Web表单客户端4

Asi*_*eed 12 webforms asp.net-identity identityserver3 asp.net-core identityserver4

我有一个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)
Run Code Online (Sandbox Code Playgroud)

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

我没有看到带有Web表单客户端示例的身份服务器4 示例

身份服务器3有一个示例, 但它在启动时正在做所有事情

当我看到身份服务器4的mvc客户端时,它在configure方法中有所有设置,然后像这样调用它

我将如何在webform中应用Authorize属性,以便将我重定向到身份服务器4进行登录,然后在登录后我调用api,如下所示:

如何更改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 });
                }
Run Code Online (Sandbox Code Playgroud)

d_f*_*d_f 3

迟到的答案,但希望它能帮助某人,仍然支持网络表单。
启动与web表单一起使用是没有问题的。唯一的限制是没有地方AuthorizeAttribute放,但这仍然不是问题,只需输入:

app.UseStageMarker(PipelineStage.Authenticate);
Run Code Online (Sandbox Code Playgroud)

在你的底部

public void Configuration(IAppBuilder app)
Run Code Online (Sandbox Code Playgroud)

OWIN Startup 中的方法。可以从我的 github 获取

示例 Startup 实现。它与 MVC、Web 表单配合使用,还从 IdentityServer v.3 的代码库中引入了 JWT 验证,并升级为使用最新的 OWIN 库进行编译。


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