Visual Studio 2015 Asp.Net MVC Web应用程序:谷歌身份验证,?不传递重定向uri

Visual Studio 2015 Asp.Net MVC Web应用程序:谷歌身份验证,?不传递重定向uri,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,我不熟悉外部登录例程,但这就是我停止的原因。在我连接Visual Studio 2015 mvc web应用程序时,非常感谢您的帮助 第一次尝试是谷歌 成功设置google: ---------from google developer page---------------- Client ID: (xxed out here) Client secret (xxedout here) Redirect URIs https://localhost:44300/tsic/Accou

我不熟悉外部登录例程,但这就是我停止的原因。在我连接Visual Studio 2015 mvc web应用程序时,非常感谢您的帮助

第一次尝试是谷歌

成功设置google:

---------from google developer page----------------
Client ID: (xxed out here)
Client secret   (xxedout here)

Redirect URIs   
https://localhost:44300/tsic/Account/ExternalLoginCallback/
https://localhost/tsic/Account/ExternalLoginCallback/

JavaScript origins  
http://localhost:54618/
https://localhost:44300/
---------end from google developer page----------------
来自客户控制员:

// POST: /Account/ExternalLogin
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{

    // Request a redirect to the external login provider.
        // Request a redirect to the external login provider.
        var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { jSeg = "tsic", ReturnUrl = returnUrl });
        var properties = SignInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
        return new ChallengeResult(provider, properties);
}
然后,我将控制器返回的URL与谷歌开发者页面返回的URL进行了比较:

from google:                 https://localhost:44300/tsic/Account/ExternalLoginCallback/
from controller in debugger: https://localhost:44300/tsic/Account/ExternalLoginCallback/
确认它们是相同的

然后执行代码,我确实可以登录到google,但立即(从chrome inspect elements的网络选项卡)获得:

查看发送到google的请求头,确认我的代码发送了错误的查询字符串“redirect_uri”:

我是否错过了一些明显的事情,或者其他人也经历过这种情况


我已经弄明白了。就我而言,这是一个误解,但我相信我的错误将为如何向其他人澄清提供一些见解:

解开这个问题的关键是 有了谷歌,mvc产生的重定向uri就变得非常有用了hostname://signin-google 对于facebook:hostname://signin-facebook

由此我得出结论,在google和facebook开发者设置页面上设置的重定向uri应该是这些值,而不是mvc代码中回调方法的位置:ExternalLoginCallback(这是我的误解)

因此,安装说明应为:

1) 将提供商(Google、Facebook)的重定向uri设置为(除了跟踪Account/ExternalLogin中ChallengeResult(提供商、属性)生成的标题外,没有其他方法知道此值)

2) 设置SignInManager的重定向URL。将ExternalAuthenticationProperties(提供程序,重定向URL)配置为ExternalLoginCallback方法的位置


重申我的错误:我认为提供者设置端(在Google或Facebook)上设置的重定向uri应该是mvc回调方法的url:ExternalLoginCallback。事实并非如此,而是必须如此protocol://hostname/signin-(提供者名称)。但是,回调方法的url:ExternalLoginCallback必须是在ExternalLogin方法调用ConfigureExternalAuthenticationProperties时使用的重定向url。

刚刚对Facebook重复了这个过程,出现了完全相同的问题,发送到facebook的重定向\u uri不是ConfigureExternalAuthenticationProperties中配置的内容:?客户端\u id=xxdout&scope=&response\u type=code&redirect\u uri=https%3A%2F%2Flocalhost%3A44300%2Fsignin facebook(这不是配置的内容)&state=xxdout您提到的方法有效,虽然它将我重定向到谷歌,我批准了登录,但我注意到,当我被重定向时,它没有显示我的姓名/电子邮件,并且仍然显示注册/登录按钮。当再次尝试登录时,我遇到以下异常:“根据验证过程,远程证书无效”。我将进一步调查,但我想我会更新这篇文章,因为它在处理这个问题上肯定是正确的。
400. That’s an error.

Error: redirect_uri_mismatch

Application: TeamSportsInfo.com

You can email the developer of this application at: ToddTSIC@gmail.com

The redirect URI in the request: https://localhost:44300/signin-google did not match a registered redirect URI.
From chrome network tools:

Remote Address:216.58.218.205:443
Request URL:https://accounts.google.com/o/oauth2/auth
?response_type=code
&client_id=xxdout
&redirect_uri=https%3A%2F%2Flocalhost%3A44300%2Fsignin-google (THIS IS INCORRECT AND IS NOT WHAT WAS SUPPLIED BY SignInManager.ConfigureExternalAuthenticationProperties)
&scope=openid%20profile%20email
&state=xxdout