ASP.net - Azure AD - Request.IsAuthenticated always false why? next

Viewed 1497

All my attempts to make working, as is, the sample "AppModelv2-WebApp-OpenIDConnect-DotNet" have failed yet. Redirection from Azure AD process seems occuring, a token is even present but "Request.IsAuthenticated" is always false.

I have checked and checked again that the required elements are correct, like the Client ID, the tenant , the URL to be redirected to . No errors of any sort are notified, I just get the homepage with the same sign in button. Access to the claims is never allowed. Any idea? Help would be greatly appreciated.

Access tokens option has been added but same result

1 Answers

Newest

I have upload my demo, you just need to replace ClientId,Tenant and redirectUri.

Regarding the value of Tenant, you can use TenantID or common. The difference is that when you use TenantID, this app can only be used by users under this tenant. common can support other tenants.

UPDATE

When you want to deploy your app. You need to modify web.config file and Redirect URIs in portal like my screenshoots.

enter image description here

enter image description here

Test Pic:

enter image description here

enter image description here

enter image description here

PRIVIOUS

After reading your problem description, it is not clear why the problem occurred.

You can follow my steps to try again, I will show you step by step, your problem should be solved.

  1. First add App Registrations in the portal.

  2. In the portal, add or modify Redirect URIs, the default value is https://localhost:44368/, and enable Access tokens and ID tokens.

enter image description here

  1. Modify the ClientId value of web.config in the project. ClientId is copied from the portal.

enter image description here

  1. Set breakpoints in the HomeController.cs and Index.cshtml files, as in the screenshot below.

enter image description here

  1. F5 run the project, see screenshots for the next steps, there will be a few notes.

Step1. Start with default page Home/Index.

enter image description here

Step2. Click Sign in with Microsoft, it will jump into breakpoint in HomeController.cs file. Because not sign in,so Request.IsAuthenticated is false.

enter image description here

Step3. When you input your account and pwd, it will redirect to Home/Index. Before that it will jump to breakpoint in Index.cshtml file. You can see the value of Request.IsAuthenticated after success login. It's true now.

enter image description here

Step4. Then you can see Index page.

enter image description here

Related