J'utilise Google OAuth comme mode d'authentification pour mon application Web .NET. Bien qu'il semble fonctionner correctement sur ma machine, sur l'environnement en direct, il semble fonctionner de façon intermittente.L'authentification Google fonctionne par intermittence
Voici les informations saisies dans la console développeur:
et l'API Google+ est configuré pour être activé:
La méthode par défaut ExternalLogin
est la suivante :
public ActionResult ExternalLogin(string provider, string returnUrl)
{
return new ChallengeResult(provider,
Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}
Alors que le ExternalLoginCallback
est défini comme suit:
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
var userEmail = loginInfo.Email;
var loggedInUser = VerifyAndAuthenticateUser(userEmail);
if (loggedInUser != null)
{
FormsAuthentication.SetAuthCookie(userEmail, false);
return RedirectToLocal(returnUrl);
}
return RedirectToAction("login", "account");
}
Et le fournisseur Google Id et secret sont remplis dans le fichier Startup.Auth.cs
:
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "xxxx",
ClientSecret = "xxxx"
});
Mon web.config
contient l'authentification des formulaires dans l'élément system.web : J'ai besoin de quelques lignes de code dans le ExternalLogin
et ExternalLoginCallback
méthodes pour se connecter où il échoue, et il semble que le ExternalLoginCallback
n'a pas pu être appelé. Encore une fois, cela se produit par intermittence car parfois je suis capable de compléter mon login. Quel pourrait être le problème?