© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago
Cyclomatic

IdentityServer4, oauth and re-logging in

Hi,

I have a web app that relies on Azure AD (Entra ID) to authenticate and authorize users in my web app.

My app looks like the following:

Angular SPA -> IdentityServer4 -> AzureAD

And

Angular SPA -> Web API

At a certain point, I need the user to re-enter their credentials. I can force the credentials to be re-entered, but the issue is that the user can log in using different credentials at that stage. I can pass the login_hint to the identityserver to prepopulate the user's email address, but they can still request to log in as a different user when the pop up window shows. I can also pass id_token_hint as well so I assume that I can use that to check whether the current logged in user is different to the one trying to log in.

What I am unsure of is how I can force an error when logging in and how I can handle it gracefully. One location I was trying is in on OnTokenValidated event of the middleware for aad (AzureAD), and I can for example set context.Fail("Some error message") but that shows an exception page. Ideally I'd like to redirect to something a bit more useful. Currently the CallbackPath of my middle where is /signin-aad. It does call back to this, but shows the exception.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ IdentityServer4
C#CC# / help
3y ago
Implementing Google OAuth throws an error after logging in
C#CC# / help
2y ago
Two Factor Authentication with IdentityServer4
C#CC# / help
3y ago
Logging in ASP.NET
C#CC# / help
2y ago