.net-core - .Net Core 3.1 作为独立的身份服务器
问题描述
我想使用 .Net Core 3.1 Web 应用程序来允许应用程序(例如 iPhone 或 Web Javascript)使用用户名和密码进行身份验证并接收包含有关用户声明的 Jason Web 令牌(JWT)......如果它成功,然后 JWT 可以作为不记名令牌发送到 API,该 API 将解码和验证 JWT(令牌将是非对称的并使用公钥/私钥对)并检索嵌入的任何声明......也许是一个奖励如果应用程序也可以解码 JWT 以检索任何声明。
关于这种方法是否可行的任何想法?而且,如果有任何关于如何做到这一点的讨论或示例,那就太好了。
解决方案
查看 IdentityServer4 提供的示例。此示例/快速入门包括您所描述的案例。https://github.com/IdentityServer/IdentityServer4/tree/main/samples/Quickstarts/6_AspNetIdentity/src
API 需要是 IdentityServer4 配置中的一个范围。它与权限 (IdentityServer4) 有连接:
services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options =>
{
options.Authority = "https://localhost:5001";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false
};
});
客户端,在本例中为 MVC 客户端,需要是 IdentityServer4 中的客户端。GrantType 有多种类型。https://identityserver4.readthedocs.io/en/latest/topics/grant_types.html
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
options.DefaultChallengeScheme = "oidc";
})
.AddCookie("Cookies")
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://localhost:5001";
options.ClientId = "mvc";
options.ClientSecret = "secret";
options.ResponseType = "code";
options.Scope.Add("api1");
options.SaveTokens = true;
});
希望这可以帮助你
推荐阅读
- animation - 如何让动画树从头开始播放动画?戈多3.2.3
- python - 我使用了 import pywhatkit 并且 sendwhatmsg 不起作用
- excel - 多重如果公式
- authentication - Firefox 如何以编程方式从其他浏览器导入登录凭据?
- pip - python jupyter notebook和colab中'%pip'和'!pip'的区别
- prolog - 忽略最后一项的两个列表的 Prolog 组合
- css - 水平居中 DIV,每边有不均匀宽度的 DIV
- reactjs - 即使分配给 extraData 的状态发生变化,FlatList 也不会重新呈现
- angular - Angular 中的 e2e 测试:在 Firefox 中使用量角器无法上传和下载文件
- python - python创建的批处理文件没有运行,但记事本可以编辑