-2
I’m having problems logging in through google and facebook when accessing through an iphone, after I authenticate my account, on google for example, callback is not called generating an exception.
This is how login works:
- The customer clicks on the button (google)
- The Externallogin function is called, passing the Provider(google) and the redirect url
- Authentication is done and the redirect url is called.
The application uses netCore 2.1, when I access the application using a desktop browser or by mobile using android everything works perfectly, but when I try to login by iphone using facebook or google is generated an exception "Correlation failed"as shown in the image below:
Startup.Cs
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite("Data Source=Auth.db"));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
string clienteID = System.Diagnostics.Debugger.IsAttached ? "Meu-id" : "Meu-id";
string clienteSECRET = System.Diagnostics.Debugger.IsAttached ? "Meu-id" : "Meu-id";
string facebookID = "Meu-id";
string facebookSECRET = "Meu-id";
services
.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
options.LoginPath = "/Home/Index";
options.Cookie.SameSite = SameSiteMode.None;
})
.AddGoogle("Google", googleOptions =>
{
googleOptions.ClientId = clienteID;
googleOptions.ClientSecret = clienteSECRET;
googleOptions.UserInformationEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo";
googleOptions.ClaimActions.Clear();
googleOptions.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
googleOptions.ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
googleOptions.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name");
googleOptions.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name");
googleOptions.ClaimActions.MapJsonKey("urn:google:profile", "link");
googleOptions.ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
googleOptions.ClaimActions.MapJsonKey("urn:google:picture", "picture", "url");
googleOptions.ClaimActions.MapJsonKey("urn:google:locale", "locale", "string");
})
.AddFacebook(facebookOptions =>
{
facebookOptions.AppId = facebookID;
facebookOptions.AppSecret = facebookSECRET;
});
services.AddTransient<IEmailSender, EmailSender>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddProgressiveWebApp();
//services.ConfigureExternalCookie(options =>
//{
// // Other options
// options.Cookie.SameSite = SameSiteMode.None;
//});
//services.ConfigureApplicationCookie(options =>
//{
// // Other options
// options.Cookie.SameSite = SameSiteMode.None;
//});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseAuthentication();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy(new CookiePolicyOptions()
{
MinimumSameSitePolicy = SameSiteMode.None
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "LoginEmpresa",
template: "{Empresa}",
//defaults: new { controller = "Account", action = "LoginPage" });
defaults: new { controller = "Home", action = "Index" });
});
}
}
Externallogin
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{
// Reque;;st a redirect to the external login provider.
var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { returnUrl });
AuthenticationProperties properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
try
{
//properties.AllowRefresh = true;
return Challenge(properties, provider);
}
catch (Exception e)
{
MetodosAuxiliares.SaveExceptionError(e, "ExternalLogin/try");
}
return null;
}