Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is Notifications in OpenIdConnectOptions in .NET Core 1.0.0 RC2?

It looks like there is breaking change in RC2.

I was trying to set up the OpenId connect using this section of old code:

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,
    };
});

But the lambda options setup is not available.

If I try to use a new 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,

});

No Notifications is there. Anyone knows what is the new setup?


Update

Based on the answer by Pinpoint, here is my updated code:

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

and the OnAuthenticationFailed method is:

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

}
like image 909
Blaise Avatar asked Oct 28 '25 09:10

Blaise


1 Answers

No Notifications is there. Anyone knows what is the new setup?

The Notifications property was renamed to Events and OpenIdConnectAuthenticationNotifications is now named OpenIdConnectEvents.

like image 161
Kévin Chalet Avatar answered Oct 31 '25 07:10

Kévin Chalet