Awscognito Login Blocked 1 Time After Logout - "Obtaining an Identity Id in Another Thread Failed or Didn't Complete Within 5 Seconds."

AWSCognito login blocked 1 time after logout - Obtaining an identity id in another thread failed or didn't complete within 5 seconds.

Finally i was able to solve this problem.

The sample project that AWSMobileHub offers to help integrate the features two classes FacebookIdentityProfile and UserPoolsIdentityProfile which inherit from AWSIdentityProfile.
The classes both have a function load() which is called automatically signs in with one of these providers. You are supposed to setup the user profile in this function.

What I did was calling a AWSDynamoDBObjectMapper.default().load(...) at first in this function to check if the user is already in my database and doesn't need any setup. I figured that this should work fine since it happens after the signup. And it worked fine with the initial sign in. But as soon as the user would sign out and sign back in, the AWSDynamoDBObjectMapper.default().load(...) and the cognito sign in would be executed parallel and somehow dynamodb would block cognito.

So what I had to do was moving the dynamodb request out of this function and make sure that it is not called before the sign in is finished.

Correlation failed in net.core / asp.net identity / openid connect

I've finally found the solution, I´ll post here just in case somebody have a similar problem.

Looks like the principal problem was that my redirect URI was the same that the CallBackPath:

"CallbackPath": "/Account/SigninOidc"

var authProperties = _signInManager
.ConfigureExternalAuthenticationProperties("AzureAD",
Url.Action("SigninOidc", "Account", null, Request.Scheme));

Well, here is my corrected Startup.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BPT.PC.IdentityServer.Data;
using BPT.PC.IdentityServer.IdentityStore;
using BPT.PC.IdentityServer.Models;
using BPT.PC.IdentityServer.Web.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;

namespace BPT.PC.IdentityServer.Web
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<User, Role>()
.AddUserStore<UserStore>()
.AddRoleStore<RoleStore>()
.AddDefaultTokenProviders();

services.AddMemoryCache();
services.AddDistributedMemoryCache();
services.AddDbContext<IdentityServerDb>
(options => options.UseSqlServer(Configuration.GetConnectionString("IdentityServerDb")));

services
.AddMvc();
services
.AddAuthentication(auth =>
{
auth.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
auth.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
auth.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect("AzureAD", "AzureAD", options =>
{
Configuration.GetSection("AzureAD").Bind(options); ;
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.RemoteAuthenticationTimeout = TimeSpan.FromSeconds(120);
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.RequireHttpsMetadata = false;
options.SaveTokens = true;
});

services.AddSingleton(Configuration.GetSection("OpenIdConnectProviderConfiguration").Get<OpenIdConnectProviderConfiguration>());

}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}

app.UseStaticFiles();
app.UseAuthentication();

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Account}/{action=Login}/{id?}");
});
}
}
}

And the finally implementation:

[HttpGet]
public IActionResult CorpLogin()
{
var authProperties = _signInManager
.ConfigureExternalAuthenticationProperties("AzureAD",
Url.Action("LoggingIn", "Account", null, Request.Scheme));

return Challenge(authProperties, "AzureAD");
}

The appsettings.json is the same.

AWSCognito login blocked 1 time after logout - Obtaining an identity id in another thread failed or didn't complete within 5 seconds.

Finally i was able to solve this problem.

The sample project that AWSMobileHub offers to help integrate the features two classes FacebookIdentityProfile and UserPoolsIdentityProfile which inherit from AWSIdentityProfile.
The classes both have a function load() which is called automatically signs in with one of these providers. You are supposed to setup the user profile in this function.

What I did was calling a AWSDynamoDBObjectMapper.default().load(...) at first in this function to check if the user is already in my database and doesn't need any setup. I figured that this should work fine since it happens after the signup. And it worked fine with the initial sign in. But as soon as the user would sign out and sign back in, the AWSDynamoDBObjectMapper.default().load(...) and the cognito sign in would be executed parallel and somehow dynamodb would block cognito.

So what I had to do was moving the dynamodb request out of this function and make sure that it is not called before the sign in is finished.



Related Topics



Leave a reply



Submit