神医皇妃 柳风拂叶,当初求种像条狗 如今撸完嫌人丑,超级修圣传奇
您可以向托管identityserver4的应用程序添加更多api端点。
您通常希望通过它们所托管的identityserver实例来保护这些api。这不是问题。只需将令牌验证处理程序添加到主机(请参阅此处):
public void configureservices(iservicecollection services) { services.addmvc(); // details omitted services.addidentityserver(); services.addauthentication() .addidentityserverauthentication("token", isauth => { isauth.authority = "base_address_of_identityserver"; isauth.apiname = "name_of_api"; }); }
在您的api上,您需要添加[authorize]
属性并显式引用您要使用的身份验证方案(在此示例中token
,您可以选择您喜欢的任何名称):
public class testcontroller : controllerbase { [route("test")] [authorize(authenticationschemes = "token")] public iactionresult get() { var claims = user.claims.select(c => new { c.type, c.value }).toarray(); return ok(new { message = "hello api", claims }); } }
如果要从浏览器调用该api,则还需要配置cors(请参阅此处)。
如果需要,您还可以将端点添加到发现文档中,例如:
services.addidentityserver(options => { options.discovery.customentries.add("custom_endpoint", "~/api/custom"); })
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论