【发布时间】:2017-09-15 01:59:18
【问题描述】:
我了解如何为 appsettings.json 配置服务并将它们注入控制器。但是,当我配置 Auth 时,我需要使用 ConfigureServices 中的值。我该怎么做?请参阅下面的示例。特别是这一行:
option.clientId = /*Need client Id from appsettings.json*/
代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<AADSettings>(Configuration.GetSection("AADSettings"));
services.Configure<APISettings>(Configuration.GetSection("APISettings"));
// Add Authentication services.
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
// Configure the OWIN pipeline to use cookie auth.
.AddCookie()
// Configure the OWIN pipeline to use OpenID Connect auth.
.AddOpenIdConnect(option =>
{
option.clientId = /*Need client Id from appsettings.json*/
option.Events = new OpenIdConnectEvents
{
OnRemoteFailure = OnAuthenticationFailed,
};
});
}
【问题讨论】:
标签: c# asp.net-core-2.0