用于用户管理的Identity Server和web api

我正在为我的项目使用Identity Server3,我目前有一个网站和api受Id服务器保护,这工作正常但是因为我将用户存储在Id Server数据库中我无法真正更改任何用户的数据从网站上更改个人资料图片或任何索赔值。

为了解决这个问题,我正在考虑在IdServer之上创建API,这个API将管理用户,更改密码,检索用户或更改与用户相关的任何内容,我想在示例项目上创建此API我有我的IdServer使用Owin映射。

现在我在/身份路线中有我的idServer

public class Startup { public void Configuration(IAppBuilder app) { Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Trace().CreateLogger(); app.Map("/identity", idserverApp => { var efConfig = new EntityFrameworkServiceOptions { ConnectionString = "IdSvr3Config" }; var options = new IdentityServerOptions { SiteName = "Identity server", IssuerUri = ConfigurationManager.AppSettings["idserver:stsIssuerUri"], PublicOrigin = ConfigurationManager.AppSettings["idserver:stsOrigen"], SigningCertificate = Certificate.Get(), Factory = Factory.Configure(efConfig), AuthenticationOptions = AuthOptions.Configure(app), CspOptions = new CspOptions { Enabled = false }, EnableWelcomePage=false }; new TokenCleanup(efConfig, 3600 * 6).Start(); idserverApp.UseIdentityServer(options); }); app.UseIdServerApi(); } } 

我的api“中间件”就是这样

 **public static class IdServerApiExtensions { public static void UseIdServerApi(this IAppBuilder app, IdServerApiOptions options = null) { if (options == null) options = new IdServerApiOptions(); if (options.RequireAuthentication) { var dic = app.Properties; JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary(); app.UseIdentityServerBearerTokenAuthentication( new IdentityServerBearerTokenAuthenticationOptions { Authority = "https://localhost:44302/identity", //here is the problem, it says not found even though I already mapped idServer to /identity RequiredScopes = new[] { "idserver-api" }, ValidationMode=ValidationMode.ValidationEndpoint }); } var config = new HttpConfiguration(); WebApiConfig.Register(config,options.RequireAuthentication); app.UseNinjectMiddleware(() => NinjectConfig.CreateKernel.Value); app.UseNinjectWebApi(config); app.Use(options); } }** 

我知道有可能我只是不知道在同一个项目上使用api是否是一个好主意,而且我也不知道该怎么做。

  • 创建此API以管理用户是一个好主意吗? 如果没有,我可以使用什么?
  • 如何创建正确的设置以启动/ api下的API,同时使用IdServer来保护此API?

更新

添加ValidationMode = ValidationMode.ValidationEndpoint ,修复了我的问题,感谢Scott Brady

谢谢

Identity Server团队的一般建议是将任何管理页面或API作为单独的项目运行( 最新的示例 )。 最佳做法是仅向Identity Server和身份管理应用程序授予对您的身份数据库/存储的访问权限。

要管理您的用户,是的,您可以编写自己的API。 其他选项是将其包含在单个MVC网站中或使用Identity Manager之类的东西。

但是,您仍然可以使用相同的应用程序方法,使用OWIN映射。 要确保这一点,您可以使用IdentityServer3.AccessTokenValidation包,使用以下代码:

 app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions { Authority = ConfigurationManager.AppSettings["idserver:stsOrigen"], RequiredScopes = new[] { "adminApi" }, ValidationMode = ValidationMode.ValidationEndpoint });