当前位置: 首页 > 编程语言 > C#

IdentityServer和用于用户管理的webapishare

时间:2023-04-11 12:00:55 C#

我将用户存储在IdServer数据库中我实际上无法从网站上更改任何用户数据来更改个人资料图片或任何声明值。为了解决这个问题,我正在考虑在IdServer之上创建API,这个API将管理用户、更改密码、检索用户或更改与用户相关的任何内容,我想在示例项目上创建这个API我有我的IdServer使用Owin地图.现在我在/身处线路中有我的idServerapp.Map("/identity",idserverApp=>{varefConfig=newEntityFrameworkServiceOptions{ConnectionString="IdSvr3Config"};varoptions=newIdentityServerOptions{SiteName="Identityserver",IssuerUri=ConfigurationManager.AppSettings["idserver:stsIssuerUri"],PublicOrigin=ConfigurationManager.AppSettings["idserver:stsOrigen"],SigningCertificate=Certificate.Get(),Factory=Factory.Configure(efConfig),AuthenticationOptions=AuthOptions.Configure(app),CspOptions=newCspOptions{Enabled=false},EnableWelcomePage=false};newTokenCleanup(efConfig,3600*6).Start();idserverApp.UseIdentityServer(options);});app.UseIdServerApi();}}我的api“中间件”就是这样**publicstaticclassIdServerApiExtensions{publicstaticvoidUseIdServerApi(thisIAppBuilderapp,IdServerApiOptionsoptions=null){if(options==null)options=newIdServerApiOptions();}如果(选项。RequireAuthentication){vardic=app.Properties;JwtSecurityTokenHandler.InboundClaimTypeMap=newDictionary();newIdentityServerBearerTokenAuthenticationOptions{Authority="https://localhost:44302/identity",//这里是问题所在,即使我已经将idServer映射到/identityRequiredScopes=new[]{"idserver-api"},它仍然说找不到ValidationMode=ValidationMode.ValidationEndpoint});}varconfig=newHttpConfiguration();WebApiConfig.Register(配置,选项。RequireAuthentication);app.UseNinjectMiddleware(()=>NinjectConfig.CreateKernel.Value);app.UseNinjectWebApi(配置);应用程序使用(选项);}}**我知道有可能我只是不知道在同一个项目上使用api是否是个好主意而且我不知道该怎么做更新添加ValidationMode=ValidationMode.ValidationEndpoint解决了我的问题,谢谢ScottBrady谢谢IdentityServer团队的一般建议是将任何管理页面或API作为单独的项目运行(最新示例)。最佳做法是仅向IdentityServer和身份管理应用程序授予对您的身份数据库/存储的访问权限。要管理您的用户,是的,您可以编写自己的API。其他选项是将其包含在单个MVC网站中或使用类似IdentityManager的东西。但是,您仍然可以使用相同的应用程序方法,使用OWIN映射。为确保这一点,可以使用IdentityServer3.AccessTokenValidation包,使用如下代码:以上是C#学习教程分享的全部内容:IdentityServer和用户管理的webapi,如果对大家有用需要了解一下更多C#学习教程,希望大家多多关注——app.UseIdentityServerBearerTokenAuthentication(newIdentityServerBearerTokenAuthenticationOptions{Authority=ConfigurationManager.AppSettings["idserver:stsOrigen"],RequiredScopes=new[]{"adminApi"},ValidationMode=ValidationMode.}Endpoint;本文来自Validation)网络收藏,不代表立场,如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:

最新推荐
猜你喜欢