gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:14:59 25 4
gpt4 key购买 nike

我有一个 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 表单用户进行身份验证,然后使用访问 token 调用 api?

我没有看到带有 web form client 的身份服务器 4 示例或 sample

身份服务器 3 有一个 sample但它在 startup 中做所有事情

当我看到 mvc client对于身份服务器 4,它具有 configure 方法中的所有设置,然后像 this 一样调用它

我将如何在 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 });
}

最佳答案

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

app.UseStageMarker(PipelineStage.Authenticate);

在你的底部
public void Configuration(IAppBuilder app)

OWIN Startup 中的方法。一个示例启动实现 could be fetched from my github .它适用于 MVC、Web 表单,并额外从 IdentityServer v.3' 代码库中引入 JWT 验证,升级为使用最新的 OWIN 库进行编译。

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

关于webforms - 带有身份服务器 4 的 asp.net Web 表单客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40792984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com