C# 拨打Facebook/Google+;

C# 拨打Facebook/Google+;,c#,facebook-login,identity,google-login,asp.net-core-2.1,C#,Facebook Login,Identity,Google Login,Asp.net Core 2.1,我正在与Facebook和Google进行集成,以便在我的应用程序中使用此应用程序登录,但当我单击supose按钮以登录Facebook或Google时,我得到了302响应,我在上查看了此响应 它被重定向到登录,而不点击ExternalLogin 这是我的Startup.cs services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddFacebook(fOptions =>

我正在与Facebook和Google进行集成,以便在我的应用程序中使用此应用程序登录,但当我单击supose按钮以登录Facebook或Google时,我得到了302响应,我在上查看了此响应

它被重定向到登录,而不点击ExternalLogin

这是我的Startup.cs

services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
    .AddFacebook(fOptions => {
        fOptions.AppId = "myAppId";
        fOptions.AppSecret = "myAppSecret";
        fOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; })
    .AddGoogle(gOptions => {
        gOptions.ClientId = "myClintId";
        gOptions.ClientSecret = "myClientSecret;
        gOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; })
    .AddCookie();
我也在使用Identity创建用户

我在AccountController上的外部登录:

public IActionResult ExternalLogin(string provider, string returnUrl)
{
    var props = new AuthenticationProperties()
    {
        RedirectUri = Url.Action("ExternalLoginCallback"),
        Items =
        {
            { "returnUrl", returnUrl },
            { "scheme", provider },
        }
    };

    return Challenge(props, provider);
}
和我的按钮,以使用各自的外部设备登录:

<div class="col_full text-center nomargin" style="margin-bottom: 5px !important">
    <a asp-action="ExternalLogin" asp-route-provider="Facebook" asp-route-returnUrl="@ViewData["ReturnUrl"]" class="button button-rounded nomargin si-facebook si-colored" style="width: 100%" type="button">
        <i class="fa fa-facebook"></i> Facebook
    </a>
</div>

<div class="col_full text-center">
    <a asp-action="ExternalLogin" asp-route-provider="Google" asp-route-returnUrl="@ViewData["ReturnUrl"]" type="button" class="button button-rounded nomargin si-google si-colored" style="width: 100%">
        <i class="fa fa-google"></i> Google
    </a>
</div>

我正在使用.NETCore2.1


解决此问题的一些方法?

这似乎是访问此路由的授权问题,您的AccountController使用属性[Authorize]?。如果是,则Authorize属性force将此控制器的任何操作的任何请求重定向到Login

为了解决这个问题,您可以只在需要对用户进行身份验证的操作中放置[Authorize],或者在ExternalLogin操作中使用[AllowAnonymous]