【发布时间】:2016-07-12 00:41:52
【问题描述】:
我在我的项目中使用 Identity Server3,我目前有一个网站和 api 受 Id 服务器保护,这工作正常但是因为我将用户存储在 Id Server 数据库中,我无法真正改变来自网站的任何用户数据,例如更改个人资料图片或任何声明价值。
为了解决这个问题,我正在考虑在 IdServer 之上创建一个 API,这个 API 将管理用户、更改密码、检索用户或更改与用户相关的任何内容,我想创建这个 API我的 IdServer 使用 Owin 映射的示例项目。
现在我的 idServer 像这样在 /identity 路由中
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<string, string>();
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<IdServerApiMiddleware>(options);
}
}**
我知道有可能我只是不知道在同一个项目上使用 api 是否是个好主意,而且我也不知道该怎么做。
- 创建此 API 来管理用户是个好主意吗?如果不是,我可以使用什么?
- 如何创建适当的设置来启动 /api 下的 API,同时使用 IdServer 保护此 api?
更新
添加 ValidationMode=ValidationMode.ValidationEndpoint,解决了我的问题,感谢 Scott Brady
谢谢
【问题讨论】:
标签: c# asp.net-web-api oauth-2.0 owin identityserver3