Getting "We couldn't sign you in" error after signing into .NET Core web app using Azure authentication

Ron Raney 5 Reputation points
2024-11-01T20:36:19.5633333+00:00

I'm trying to retrofit Azure authentication into a .NET Core v8 web application.

I'm using this tutorial: https://learn.microsoft.com/en-us/entra/identity-platform/tutorial-web-app-dotnet-call-api?tabs=visual-studio%2Cdotnet6

I have an application set up in Entra. I've done everything in the tutorial but I'm not sure how to add the Index.html.cs code to an existing Home controller which is the default landing page. I'm guessing this could be part of the problem, but perhaps there is a network or configuration issue.

I've gone through this tutorial over 20 times trying to get it to work. I get different results in localhost and our test server. What's important is getting it to work on a real server.

When I go to our app URL, it brings up the "login.microsoftonline.com" Sign in for our organization. I am asked to sign in. Once I enter password (and bypass Stay signed in), it appears to go into a loop for about 10 seconds then it shows the "Pick an account" prompt. It shows that I'm signed in, but it says, "We couldn't sign you in. Please try again".

Developer technologies | ASP.NET | ASP.NET Core
{count} votes

3 answers

Sort by: Most helpful
  1. Q&A Assist
    2024-11-01T20:36:19.5766667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    It sounds like you're encountering a common issue related to Azure authentication in your .NET Core application. The "We couldn't sign you in" error can often be attributed to misconfigurations in your application or the Azure AD setup. Here are some troubleshooting steps you can take:

    1. Check Configuration: Ensure that your application settings in Azure AD (like the Redirect URI, Client ID, and Tenant ID) match exactly with what you have in your application. Any mismatch can lead to authentication failures.
    2. Review Logs: Enable detailed logging in your application to capture any errors during the authentication process. This can provide insights into what might be going wrong.
    3. Network Issues: Since you mentioned different results on localhost versus your test server, ensure that the server is correctly configured to allow traffic to and from Azure AD. Check firewall settings and network configurations.
    4. Inspect the Authentication Flow: Use browser developer tools to inspect network requests during the authentication process. Look for any failed requests or error messages that might indicate what is causing the loop or failure.
    5. Application Manifest: If you are using Microsoft Entra ID, ensure that the application manifest is correctly configured to allow public clients if necessary. This can be a common source of issues.
    6. Consult Documentation: Since you are following a tutorial, double-check each step to ensure nothing was missed, especially regarding the integration of the Index.html.cs code into your existing Home controller.

    If you continue to experience issues, consider reaching out to community forums like Stack Overflow or the ASP.NET Core Slack Team for additional support.


    References:

    0 comments No comments

  2. Bruce (SqlWork.com) 78,311 Reputation points Volunteer Moderator
    2024-11-05T16:42:58.38+00:00

    it sounds like the web app can not validate the code sent to the reply url. check that the web server has access to the azure oauth server. you may need to change firewall rules. also if the production server is a web farm, you will need to configure data protection services for a farm support.


  3. Anonymous
    2024-11-06T06:21:02.0766667+00:00

    Hi @Ron Raney,

    Thanks for your patience, I have test it in my local and reproduce the same issue.

    After checking the error message in output window, we found the issue is related to permission. Here is my error message.

    The user or administrator has not consented to use the application with ID '63f****-7**2-4**d-a**0-60*****8dbbc' named 'identity-client-web-app'. Send an interactive authorization request for this user and resource.
    

    Then I grant admin consent like below, and it starts to work. If you don't have the admin permission, you can contact your administrator help you.

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Jason


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.