.net-core - 如何使用从 IdentityServer 获取的令牌授权用户?
问题描述
我已经使用以下配置创建了一个 IdentityServer 项目( B ):
new Client
{
ClientId = "ro.client",
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes = { "api1" }
}
我有项目 B 的自定义登录页面,当用户输入他/她的用户和密码时,我将此信息发送到项目 B 的后端,通过此代码我可以从身份服务器获取令牌 - 项目 A:
var client = new HttpClient();
var disco = await client.GetDiscoveryDocumentAsync(_configuration["App:Authority"]);
if (disco.IsError)
{
throw new System.Exception("get info from identity server is failed.");
}
var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
{
Address = disco.TokenEndpoint,
ClientId = "ro.client",
ClientSecret = "secret",
UserName = "bob",
Password = "Pass123$",
Scope = "api1"
});
var accessToken = tokenResponse.AccessToken;
现在我想要实现的是,我以某种方式使该用户获得授权并将令牌保存在 cookie 中,因此当该用户调用另一个具有授权属性的操作时,不会将他/她重定向到登录页面。我怎样才能做到这一点?
解决方案
推荐阅读
- python-3.x - 如何使用此深度优先搜索代码来获得拓扑排序?
- angular - 如何将亚马逊会员服务集成到我的 Angular 应用程序中?
- reactjs - react.js 重定向内部函数
- hive - hive metadatastore 会自动发现新添加的数据吗?
- python - 我的 CSV 数据看起来不错,但是当我绘制图表时,数据似乎不正确
- python - 无法使用原子编辑器运行 linter-flake8
- c# - 而不是违反唯一密钥需要显示正确的消息
- ios - 登录过程完成后如何更改视图
- blast - blastpgp 中的错误:未生成空输出文件和检查点文件
- java - javax.persistence.TransactionRequiredException:执行更新/删除查询,不能激活事务