- Newest
- Most votes
- Most comments
It seems you're on the right track with integrating Amazon Cognito into your ASP.NET WebForms application, but there are a few adjustments you can make to ensure User.Identity.IsAuthenticated returns true after successful login.
-
Make sure you're using the correct AuthenticationType. Instead of CookieAuthenticationDefaults.AuthenticationType, try using "Cookies" explicitly:
app.SetDefaultSignInAsAuthenticationType("Cookies");
-
In your OpenIdConnectAuthenticationOptions, add the following settings:
ResponseType = "code id_token", Scope = "openid email profile", SaveTokens = true,
-
Ensure that your Cognito User Pool is configured correctly with the right app client settings, including the correct callback URL.
-
After the user is redirected back to your application, you may need to manually sign in the user. You can do this by adding a method to handle the OpenIdConnectAuthenticationNotification events:
Notifications = new OpenIdConnectAuthenticationNotifications { AuthorizationCodeReceived = async n => { var identity = await n.AuthenticationTicket.GetIdentityAsync(); var props = new AuthenticationProperties(); n.OwinContext.Authentication.SignIn(props, identity); } }
-
Make sure you're calling app.UseAuthentication() and app.UseAuthorization() in the correct order in your Startup.cs file.
If User.Identity.IsAuthenticated is still false after these changes, you may need to debug the authentication flow to ensure the identity is being properly set after the Cognito redirect. Also, check if you're accessing User.Identity.IsAuthenticated in the correct lifecycle method of your WebForms page, as it may not be available immediately after the redirect.
Sources
Amazon Cognito Identity Provider examples using SDK for .NET - AWS SDK Code Examples
Implement Role-based Access Control for .NET applications with Amazon Cognito | .NET on AWS Blog
How authentication works with Amazon Cognito - Amazon Cognito
Relevant content
- asked a year ago
- asked 2 years ago
- asked 3 years ago