Thanks for posting your question in the Microsoft Q&A forum.
You can override the OnRedirectToIdentityProvider
event to customize the redirection logic:
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
//// Enable the application to use a cookie to store information for the signed in user
//// and to use a cookie to temporarily store information about a user logging in with a third party login provider
//// Configure the sign in cookie
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var val = Environment.GetEnvironmentVariable("APPSETTING_USER_TIMEOUT_HOURS");
int timoutInHours = 168;// 1 week
if (!string.IsNullOrEmpty(val))
{
timoutInHours = Convert.ToInt32(val);
}
switch (authMode)
{
// other cases removed for clarity
case "openId":
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
//Scope = OpenIdConnectScope.OpenIdProfile,
//// ResponseType is set to request the code id_token - which contains basic information about the signed-in user
//ResponseType = OpenIdConnectResponseType.CodeIdToken,
Events = new OpenIdConnectAuthenticationEvents
{
OnRedirectToIdentityProvider = context =>
{
if (!context.HttpContext.User.Identity.IsAuthenticated)
{
context.Response.Redirect("/Login.aspx");
}
return Task.FromResult(0);
}
}
...
});
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
// This makes any middleware defined above this line run before the Authorization rule is applied in web.config
app.UseStageMarker(PipelineStage.Authenticate);
break;
}
}
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful