![](/img/trans.png)
[英]IdentityServer3 Authorize in custom MVC controller in identity server application
[英]IdentityServer3 Custom OWIN Middleware with additional MVC controllers
我已经实现了Identity Server 3,其中取决于所请求的URL,可以为IDS提供不同的设置(配置选项等)。
这按原样工作正常,但是我在向应用程序中添加MVC控制器/页面时遇到了问题(如https://github.com/IdentityServer/IdentityServer3/issues/1140所述)-当我尝试加载MVC控制器/页面时,出现404异常新的一页。 如果我替换coreApp.Use<IdentityServerWithTenantSwitchingMiddleware>(coreApp.Properties);
与coreApp.UseIdentityServer(new IdentityServerWithTenantSwitchingMiddleware(null, null).GetOptions());
它按预期工作,我确定问题出在IdentityServerWithTenantSwitchingMiddleware
实现Invoke
时。
在我看来,好像我在某个地方缺少一些引导程序/安装程序,告诉我我想使用MVC控制器。 或者其他的东西。 我在( https://github.com/IdentityServer/IdentityServer3/issues/1934 )上看到了几个类似的问题/问题,但都与这个确切的问题无关。
我使用GitHub上的IdentityServer3 CustomUserService重现了此问题- 请参阅我的CustomUserService演示叉 (特别是IdentityServerWithTenantSwitchingMiddleware.cs和Startup.cs )。 如果您登录到演示(密码/用户名:alice),则可以看到此问题-尝试渲染eula页面时会引发异常。
我将在下面包括一些重要的代码:
启动文件
public void Configuration(IAppBuilder app)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Trace()
.CreateLogger();
app.Map("/core", coreApp =>
{
coreApp.Use<IdentityServerWithTenantSwitchingMiddleware>(coreApp.Properties);
});
}
IdentityServerWithTenantSwitchingMiddleware
public override Task Invoke(IOwinContext context)
{
var app = new AppBuilder();
//Do some magic based on current request
var options = GetOptions();
_properties.ForEach(kvp =>
{
if (!app.Properties.ContainsKey(kvp.Key))
{
app.Properties.Add(kvp.Key, kvp.Value);
}
});
app.UseIdentityServer(options);
return app.Build()(context.Environment);
}
private IdentityServerOptions GetOptions()
{
var factory = new IdentityServerServiceFactory()
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get());
// different examples of custom user services
var userService = new EulaAtLoginUserService();
// note: for the sample this registration is a singletone (not what you want in production probably)
factory.UserService = new Registration<IUserService>(resolver => userService);
var options = new IdentityServerOptions
{
SiteName = "IdentityServer3 - CustomUserService",
SigningCertificate = Certificate.Get(),
Factory = factory,
AuthenticationOptions = new AuthenticationOptions
{
LoginPageLinks = new LoginPageLink[] {
new LoginPageLink{
Text = "Register",
Href = "localregistration"
}
}
},
EventsOptions = new EventsOptions
{
RaiseSuccessEvents = true,
RaiseErrorEvents = true,
RaiseFailureEvents = true,
RaiseInformationEvents = true
}
};
return options;
}
任何/所有帮助/建议表示赞赏。
亚历克斯
找到了我问题的答案。
取自https://github.com/damianh/DynamicKatanaPipeline-好像我没有在管道中进行下一步。 如果可以帮助任何人,请在这里工作代码:
public override Task Invoke(IOwinContext context)
{
var app = ConfigurePipeline(context);
var dynamicAppFunc = app.Build();
return dynamicAppFunc(context.Environment);
}
private IAppBuilder ConfigurePipeline(IOwinContext context)
{
var app = new AppBuilder();
app.UseIdentityServer(GetOptions(context));
app.Run(_next.Invoke);
return app;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.