![](/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.