简体   繁体   English

facebook的社交登录不在ASP.Net MVC 5项目中工作

[英]Social Login of facebook not working in ASP.Net MVC 5 project

I am going through a tutorial to implement facebook social log in my sample web site. 我正在通过一个教程在我的示例网站中实现facebook社交日志。 Below are the steps I did. 以下是我所做的步骤。

  1. Pointed my localhost application to https and allowed fake SSL in VS. 将我的localhost应用程序指向https并允许VS中的假SSL。
  2. Created a web app in facebook developer web site and noted down the secret key and id. 在Facebook开发人员网站上创建了一个Web应用程序,并记下了密钥和ID。
  3. Added my application localhost URL in the URL section of the dashboard in facebook 在facebook的仪表板的URL部分添加了我的应用程序localhost URL
  4. I added key and id in the starup.Auth.cs file in my ASP.Net MVC-5 project . 我在ASP.Net MVC-5项目的starup.Auth.cs文件中添加了key和id。

Behavour: Now when I run my application from local host (https) and click Register then I see the facebook sign in button . 行为:现在当我从本地主机(https)运行我的应用程序并click Register然后我看到facebook sign in button Also when I click that button a facebook pop up comes with "Sample App" wants to access your facebook data . 此外,当我点击该按钮时,一个Facebook弹出窗口附带“Sample App”想要访问你的facebook数据 So far so good. 到现在为止还挺好。 But as I say YES to it nothing happens after that. 但正如我说的YES它没有后出现这种情况。 I get redirected to the log in page. 我被重定向到登录页面。 and the URL is https://localhost:44393/Account/Login#_=_ URL为https://localhost:44393/Account/Login#_=_

Expected Behaviour: For the tutorial that I am following after doing above steps one message comes on tutors screen as "Facebook has authenticated.... Enter you email to continue". 预期的行为:对于我在执行上述步骤后遵循的教程,在教师屏幕上显示一条消息,因为“Facebook已经过身份验证....请输入您的电子邮件以继续”。 Something like this. 像这样的东西。 Can some one please guide me here why I am not getting same message and why I am not able to use social log in. I have tried to follow all the steps. 有人可以在这里指导我为什么我没有得到相同的消息以及为什么我无法使用社交登录。我试图遵循所有步骤。

Expected Screenshot from tutorial 预期的教程截图 在此输入图像描述

Is there any other steps I need to do in facebook developer dashboard? 在facebook开发人员仪表板中我还需要做任何其他步骤吗?

EDIT 1 : 编辑1:

In the facebook developer dashboard for my app in the Facbook Login Tab->Settings : I see below message. 在Facbook登录选项卡 - >设置中我的应用程序的Facebook开发人员仪表板中:我看到以下消息。

在此输入图像描述

EDIT 2: I debugged and found that returnURL is null when I click on facebook log in button. 编辑2:我调试并发现当我点击Facebook登录按钮时returnURL

   [AllowAnonymous]
        public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
            if (loginInfo == null)
            {
                return RedirectToAction("Login");
            }

            // Sign in the user with this external login provider if the user already has a login
            var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);

Ok, After research I found out that I need to install package Install-Package Microsoft.Owin.Security.Facebook from nuget package manager. 好的,经过研究我发现我需要从nuget包管理器安装包Install-Package Microsoft.Owin.Security.Facebook After this everything worked fine. 在此之后一切正常。

Simply update the Windows.Owin.Security.Facebook to latest version(3.1.0) further in facebook application update the "Valid OAuth redirect URIs" to " http://localhost:xxxx/signin-facebook " (in my case) every thing works... 只需在Windows应用程序中将Windows.Owin.Security.Facebook更新到最新版本(3.1.0),将“有效OAuth重定向URI”更新为“ http:// localhost:xxxx / signin-facebook ”(在我的情况下)事情有效......

OR 要么

Please see the link ExternalLoginConfirmation returns null after facebook succesful login 在facebook成功登录后,请查看链接ExternalLoginConfirmation返回null

您还可能需要在Facebook应用程序上将URI localhost添加到Valid OAuth ...以在登录成功时返回您的应用程序。

UPDATE 07/18/2018: 更新07/18/2018:

In my case I had to update nuget packages: 在我的情况下,我不得不更新nuget包:

  • Microsoft.Owin to version 4.0.0 Microsoft.Owin到版本4.0.0
  • Microsoft.Owin.Host.SystemWeb to version 4.0.0 Microsoft.Owin.Host.SystemWeb到版本4.0.0
  • Microsoft.Owin.Security to version 4.0.0 Microsoft.Owin.Security到版本4.0.0
  • Microsoft.Owin.Security.Cookies to version 4.0.0 Microsoft.Owin.Security.Cookies到版本4.0.0
  • Microsoft.Owin.Security.Facebook to version 4.0.0 Microsoft.Owin.Security.Facebook到版本4.0.0
  • Microsoft.Owin.Security.OAuth to version 4.0.0 Microsoft.Owin.Security.OAuth到版本4.0.0
  • Newtonsoft.Json to version 11.0.2 Newtonsoft.Json到版本11.0.2

big help for me was to check Event Viewer (eventvwr.msc) where I saw actual reason for HTTP 500 when facebook redirected back to my site with url: http://localhost:7566/signin-facebook 对我来说很大的帮助就是检查事件查看器(eventvwr.msc),当我用url重定向回我的网站时,我看到HTTP 500的实际原因: http:// localhost:7566 / signin-facebook

Error log was: 错误日志是:

Exception information: 
    Exception type: FileLoadException 
    Exception message: Could not load file or assembly 'Newtonsoft.Json, 
Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its 
dependencies. The located assembly's manifest definition does not match the assembly 
reference. (Exception from HRESULT: 0x80131040)
   at Microsoft.Owin.Security.Facebook.FacebookAuthenticationHandler. 
<AuthenticateCoreAsync>d__0.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.Start[TStateMachine] 
(TStateMachine& stateMachine)
   at 

Microsoft.Owin.Security.Facebook.FacebookAuthenticationHandler.AuthenticateCoreAsync()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& 
initialized, Object& syncLock, Func`1 valueFactory)
   at 
Microsoft.Owin.Security.Infrastructure.AuthenticationHandler.AuthenticateAsync()
   at Microsoft.Owin.Security.Facebook.FacebookAuthenticationHandler. 
<InvokeReplyPathAsync>d__19.MoveNext()
...

after this I updated also Newtonsoft.Json and facebook authentication through OWIN started to work for me. 在此之后,我更新了Newtonsoft.Json和通过OWIN的facebook身份验证开始为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM