.NET Core 1.0.0 RC2中的OpenIdConnectOptions中的通知在哪里?

时间:2016-05-31 20:41:18

标签: asp.net-core asp.net-core-mvc

看起来RC2发生了重大变化。

我试图使用旧代码的这一部分设置OpenId连接:

app.UseOpenIdConnectAuthentication(options =>
{
    options.ClientId = Configuration.Get("AzureAd:ClientId");
    options.Authority = String.Format(Configuration.Get("AzureAd:AadInstance"), Configuration.Get("AzureAd:Tenant"));
    options.PostLogoutRedirectUri = Configuration.Get("AzureAd:PostLogoutRedirectUri");
    options.Notifications = new OpenIdConnectAuthenticationNotifications
    {
        AuthenticationFailed = OnAuthenticationFailed,
    };
});

但lambda选项设置不可用。

如果我尝试使用新的OpenIdConnectOptions

var clientId = Configuration.GetSection("AzureAD:ClientId").Value;
var azureADInstance = Configuration.GetSection("AzureAD:AzureADInstance").Value;
var tenant = Configuration.GetSection("AzureAD:Tenant").Value;
var postLogoutRedirectUrl = Configuration.GetSection("AzureAD:PostLogoutRedirectUrl").Value;

var authority = $"{azureADInstance}{tenant}";
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    ClientId = clientId,
    Authority = authority,
    PostLogoutRedirectUri = postLogoutRedirectUrl,

});

没有Notifications。任何人都知道新的设置是什么?

更新

根据Pinpoint的回答,这是我更新的代码:

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    ClientId = clientId,
    Authority = authority,
    PostLogoutRedirectUri = postLogoutRedirectUrl,
    Events = new OpenIdConnectEvents
    {
        OnAuthenticationFailed = OnAuthenticationFailed
    }
});

并且OnAuthenticationFailed方法是:

private static Task OnAuthenticationFailed(AuthenticationFailedContext context)
{
    context.HandleResponse();
    context.Response.Redirect($"/Home/Error?message={context.Exception.Message}");
    return Task.FromResult(0);

}

1 个答案:

答案 0 :(得分:3)

  

没有通知。任何人都知道新的设置是什么?

Notifications属性已重命名为EventsOpenIdConnectAuthenticationNotifications现已命名为OpenIdConnectEvents