C# 如何处理Google OAuth2身份验证中的授权错误?

C# 如何处理Google OAuth2身份验证中的授权错误?,c#,error-handling,asp.net-mvc-5,authorization,google-oauth,C#,Error Handling,Asp.net Mvc 5,Authorization,Google Oauth,我需要一些帮助来处理谷歌认证错误 我在ASP.NETMVC5Web应用程序中集成了Google身份验证。我将应用程序类型限制为内部使用,因此只有同事才能使用他们的工作帐户登录(我们公司的电子邮件是GMail),只要我使用我的工作帐户登录,一切都正常 当我尝试使用其他(非公司)帐户登录时,正如预期的那样,我会收到一个授权错误。我的问题是,错误是来自谷歌的一个页面,没有回调到我的应用程序 我在互联网上搜索了很长一段时间,但我似乎找不到如何设置我的应用程序,因为我收到了授权错误的回调。我开始怀疑这是否

我需要一些帮助来处理谷歌认证错误

我在ASP.NETMVC5Web应用程序中集成了Google身份验证。我将应用程序类型限制为内部使用,因此只有同事才能使用他们的工作帐户登录(我们公司的电子邮件是GMail),只要我使用我的工作帐户登录,一切都正常

当我尝试使用其他(非公司)帐户登录时,正如预期的那样,我会收到一个授权错误。我的问题是,错误是来自谷歌的一个页面,没有回调到我的应用程序

我在互联网上搜索了很长一段时间,但我似乎找不到如何设置我的应用程序,因为我收到了授权错误的回调。我开始怀疑这是否有可能

有人能帮我解决这个问题吗?我不确定它是否相关,但这是我的Startup.Auth.cs中的ConfigureAuth类

public void ConfigureAuth(IAppBuilder应用程序)
{
app.CreatePerOwinContext(ApplicationDbContext.Create);
app.CreatePerOwinContext(ApplicationUserManager.Create);
app.CreatePerOwinContext(ApplicationSignInManager.Create);
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=DefaultAuthenticationTypes.ApplicationOkie,
LoginPath=新路径字符串(“/Account/Login”),
Provider=新CookieAuthenticationProvider
{
OnValidateIdentity=SecurityStampValidator.OnValidateIdentity(
validateInterval:TimeSpan.FromMinutes(30),
regenerateIdentity:(管理器,用户)=>user.GenerateUserIdentityAsync(管理器))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie,TimeSpan.FromMinutes(5));
app.useTowFactoryMemberBrowserCookie(DefaultAuthenticationTypes.TwoFactoryRememberBrowserCookie);
GoogleOAuth2AuthenticationOptions _options=新的GoogleOAuth2AuthenticationOptions()
{
ClientId=“ClientId.apps.googleusercontent.com”,
ClientSecret=“ClientSecret”
};
_选项。范围。添加(“配置文件”);
_选项。范围。添加(“电子邮件”);
_options.CallbackPath=新路径字符串(“/Account/LoginResult”);
_options.Provider=新的GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated=异步上下文=>
{
字符串索赔类型;
bool-bAddClaim=false;
foreach(context.User中的var声明)
{
claimType=string.Empty;
bAddClaim=假;
开关(认领钥匙)
{
案例“图片”:
claimType=“图片”;
bAddClaim=真;
打破
}
如果(bAddClaim)
{
string-claimValue=claim.Value.ToString();
if(!context.Identity.HasClaim(claimType,claimValue))
context.Identity.AddClaim(新系统.Security.Claims.Claim(claimType,claimValue,“XmlSchemaString”,“Google”));
}
}
}
};
app.UseGoogleAuthentication(_选项);
}
我不知道还有什么代码是相关的,所以请询问您是否遗漏了什么


提前谢谢

不知道你是否看到过这个帖子说的是关于在google开发者仪表板中设置回调url的内容是的,我看到过,但是回调url只在成功登录时使用。当出现错误时,根本没有回调