Our application is the following:
- Identity.Web (localhost:5555) - .Net Core 3.1: it has razor pages for login and password reset. We are using Identity Server 4 (Code flow - Oauth 2.0, OpenId).
- Web.Api (localhost:4500) .Net Core 3.1: basically has the resource APIs
- Angular 8 (localhost:4200): using open-id client to authenticate and access the resource APIs.
Our application used to work perfectly prior to the Chrome SameSite Updates. Now, whenever we input the username password and login (Identity.Web - localhost:5555), the browser redirects to (Angular 8 - localhost:4200), then back directly to login page.
Before, there used to be an auth-callback, then login to dashboard.
You can find below our configuration:
Identity.Web (config.cs)
var redirectUris = new List<string> { frontendUrl + "/auth-callback", frontendUrl + "/silent-refresh.html" };
var allowedCorsOrigins = new List<string> { frontendUrl };
var postLogoutRedirectUris = new List<string> { frontendUrl + "/signout-callback-oidc" };
return new List<Client>
{
new Client
{
RequireConsent = false,
ClientId = "angular_spa",
ClientName = "Angular 4 Client",
AllowedGrantTypes = GrantTypes.Code,
RequirePkce = true,
RequireClientSecret = false,
AllowedScopes = new List<string> {"openid", "profile", "api1"},
RedirectUris = redirectUris,
PostLogoutRedirectUris = postLogoutRedirectUris,
AllowedCorsOrigins = allowedCorsOrigins,
AllowAccessTokensViaBrowser = true,
}
};
Identity.Web (Startup.cs)
var settings = Configuration.GetSection(nameof(MongoDbSettings)).Get<MongoDbSettings>();
var mongoDbContext = new MongoDbContext(settings.ConnectionString, settings.DatabaseName);
services.AddIdentity<ApplicationUser, MongoIdentityRole>()
.AddMongoDbStores<ApplicationUser, MongoIdentityRole, Guid>(mongoDbContext)
.AddDefaultTokenProviders();
services.Configure<MongoSettings>(options =>
{
options.ConnectionString = Configuration.GetSection("MongoDbSettings:ConnectionString").Value;
options.DatabaseName = Configuration.GetSection("MongoDbSettings:DatabaseName").Value;
});
services.AddIdentityServer(options => { options.Events.RaiseSuccessEvents = true; })
.AddDeveloperSigningCredential()
.AddAspNetIdentity<ApplicationUser>()
.AddProfileService<ProfileService>()
.AddMongoRepository()
.AddClients()
.AddIdentityApiResources();
Web.Api (Startup.cs)
services.AddAuthentication()
.AddIdentityServerAuthentication("api1", options =>
{
options.Authority = Configuration.GetSection("IdentityServer:BaseUrl").Value;
options.RequireHttpsMetadata = false;
options.ApiName = "api1";
options.TokenRetriever = (request) =>
{
string token = TokenRetrieval.FromAuthorizationHeader().Invoke(request);
if (string.IsNullOrEmpty(token))
{
token = TokenRetrieval.FromQueryString().Invoke(request);
}
return token;
};
});
Note: Everything works perfectly in Firefox. We read this article, and applied what's there, but it didn't work.