【发布时间】:2016-12-31 21:18:30
【问题描述】:
我正在使用 Google OAuth 作为我的 .NET Web 应用程序的身份验证模式。虽然它似乎在我的机器上运行良好,但在实时环境中它似乎间歇性地运行。
以下是在开发者控制台中输入的详细信息:
并且 Google+ API 已设置为启用:
默认ExternalLogin方法如下:
public ActionResult ExternalLogin(string provider, string returnUrl)
{
return new ChallengeResult(provider,
Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
}
而ExternalLoginCallback的定义如下:
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");
}
并且在Startup.Auth.cs文件中填写了Google provider Id和Secret:
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "xxxx",
ClientSecret = "xxxx"
});
我的web.config 在 system.web 元素中包含表单身份验证:
<authentication mode="Forms">
<forms loginUrl="~/account/login" timeout="2880" />
</authentication>
我在ExternalLogin 和ExternalLoginCallback 方法中添加了几行代码来记录失败的地方,似乎ExternalLoginCallback 调用失败。同样,这会间歇性地发生,因为有时我能够完成我的登录。可能是什么问题?
【问题讨论】:
标签: c# asp.net-mvc oauth google-authentication