Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Asp.Net OWIN OnAuthenticationFailed
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ResponseType = OpenIdConnectResponseType.CodeIdToken,
ClientId = clientId,
Authority = Authority,
//...
Notifications = new OpenIdConnectAuthenticationNotifications()
{
// If there is a code in the OpenID Connect response, redeem it for an access token
AuthorizationCodeReceived = (context) =>
{
// ...
},
// On Authentication Failed
AuthenticationFailed = (context) =>
{
String ErrorMessage = context.Exception.Message;
String InnerErrorMessage = String.Empty;
String RedirectError = String.Format("error_message={0}", ErrorMessage);
if (context.Exception.InnerException != null)
{
InnerErrorMessage = context.Exception.InnerException.Message;
RedirectError = String.Format("{0}&inner_error={1}", RedirectError, InnerErrorMessage);
}
// or you can just throw it
// throw new Exception(RedirectError);
RedirectError = RedirectError.Replace("\r\n", " ");
context.Response.Redirect("/?" + RedirectError);
context.HandleResponse();
return Task.FromResult(0);
}
}
});
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.