So I follow the official
guide on creating an ASP.NET MVC project and enabling Facebook authentication, by Rick Anderson of Microsoft. I am able to authenticate with Facebook, but I still can't sign in. The problem seems to be that I do not get the registration form when I authenticate
for the first time.
I create a new ASP.NET MVC project.
I enable individual user accounts.
I update OWIN from 3.0.1 to 4.0.0.
I add RequireHttps attribute to the Home controller.
I enable SSL.
I copy the HTTPS URL and paste it in as the project URL.
I create a new Facebook app, add Facebook Login (OAuth) and configure it for my localhost app.
I enable the UseFacebookAuthentication method and add my app ID and app secret.
The problem seems to be that I do not get the registration form when I authenticate for the first time. So when I click on the Facebook sign in button, the URL changes from https://localhost:44333/Account/Login to https://localhost:44333/Account/Login#_=_
and no registration form is displayed.
What am I missing?
Updating OWIN
Enabling SSL
Adding API key and authenticating
FYI
If you are a frustrated ASP.NET beginner like myself, and you stumbled across this post in search for answers, please make note that the guide I linked to above is 2 years, 11 months and 20 days old at the time of this writing. It's amazing how fast things
get outdated. One thing you need to do that's not mentioned in the guide is that you need to provide a valid redirect URI. I believe this is a new requirement for OAuth 2.0. If you fail to do that, you will run into the problem you see below when you try to
authenticate.
All you really need to do is add the local HTTPS address for your app as you see below.
This is not an answer to the question, but it clearly shows that something about Facebook login is broken. Because I can add Google login and it works just fine, as you can see from the images below.
So what should I do about Facebook login? Why is it not working? What's wrong with it? I have already updated OWIN to the latest version, I am using SSL, and I did add OAuth redirect URI accordingly. What else can I do?
Why is Google login working but not Facebook login? Why am I not redirected to the ExternalLoginCallback? This appears to be an async method in the Account controller.
Only after adding Google login does my AspNetUsers and AspNetUserLogins table get populated, after I fill out the form and register my new Google authenticated user.
But why is the same not working with Facebook? What's the problem? I can repeat the same process any number of times, starting all over from scratch with a new ASP.NET MVC project, the outcome will be the same, Facebook login will not work. In complete contrast
to ASP.NET Core Razer Pages project, where I am able to enable and login with Facebook, Google and Twitter. Is the ASP.NET MVC project template simply too old and outdated for use with Facebook login today? Should it not be enough to just update OWIN to the
latest version and get it working with the latest Facebook API?
For the record, I am using Visual Studio Community edition, 15.5.5 on Windows 10 Pro, v. 1709, .NET target 4.6.1.
The Microsoft.Owin.Security.Facebook namespace provides types related to Facebook authentication.
Regards,
Angie
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
2 Points
7 Posts
How to sign in with Facebook account in an ASP.NET MVC project?
Feb 24, 2018 04:09 PM|samirgunic|LINK
Hi!
So I follow the official guide on creating an ASP.NET MVC project and enabling Facebook authentication, by Rick Anderson of Microsoft. I am able to authenticate with Facebook, but I still can't sign in. The problem seems to be that I do not get the registration form when I authenticate for the first time.
The problem seems to be that I do not get the registration form when I authenticate for the first time. So when I click on the Facebook sign in button, the URL changes from https://localhost:44333/Account/Login to https://localhost:44333/Account/Login#_=_ and no registration form is displayed.
What am I missing?
Updating OWIN
Enabling SSL
Adding API key and authenticating
FYI
If you are a frustrated ASP.NET beginner like myself, and you stumbled across this post in search for answers, please make note that the guide I linked to above is 2 years, 11 months and 20 days old at the time of this writing. It's amazing how fast things get outdated. One thing you need to do that's not mentioned in the guide is that you need to provide a valid redirect URI. I believe this is a new requirement for OAuth 2.0. If you fail to do that, you will run into the problem you see below when you try to authenticate.
All you really need to do is add the local HTTPS address for your app as you see below.
Member
2 Points
7 Posts
Re: How to sign in with Facebook account in an ASP.NET MVC project?
Feb 24, 2018 06:19 PM|samirgunic|LINK
This is not an answer to the question, but it clearly shows that something about Facebook login is broken. Because I can add Google login and it works just fine, as you can see from the images below.
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "blablabla.googleusercontent.com",
ClientSecret = "blablabla"
});
So what should I do about Facebook login? Why is it not working? What's wrong with it? I have already updated OWIN to the latest version, I am using SSL, and I did add OAuth redirect URI accordingly. What else can I do?
Why is Google login working but not Facebook login? Why am I not redirected to the ExternalLoginCallback? This appears to be an async method in the Account controller.
Only after adding Google login does my AspNetUsers and AspNetUserLogins table get populated, after I fill out the form and register my new Google authenticated user.
But why is the same not working with Facebook? What's the problem? I can repeat the same process any number of times, starting all over from scratch with a new ASP.NET MVC project, the outcome will be the same, Facebook login will not work. In complete contrast to ASP.NET Core Razer Pages project, where I am able to enable and login with Facebook, Google and Twitter. Is the ASP.NET MVC project template simply too old and outdated for use with Facebook login today? Should it not be enough to just update OWIN to the latest version and get it working with the latest Facebook API?
For the record, I am using Visual Studio Community edition, 15.5.5 on Windows 10 Pro, v. 1709, .NET target 4.6.1.
All-Star
32817 Points
3815 Posts
Re: How to sign in with Facebook account in an ASP.NET MVC project?
Feb 27, 2018 06:21 AM|Angie xu - MSFT|LINK
Hi,
Have you tried installing package
Install-Package Microsoft.Owin.Security.Facebook
from nuget package manager?
The Microsoft.Owin.Security.Facebook namespace provides types related to Facebook authentication.
Regards,
Angie
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Contributor
5290 Points
2307 Posts
Re: How to sign in with Facebook account in an ASP.NET MVC project?
Feb 27, 2018 08:43 AM|AngelinaJolie|LINK
Hi samirgunic,
Sir, before, I tested an working example with facebook account. and met the same error as yours
Solution
please add more URLs to it, and I think http://localhost:**/Account/Login is required beside http://localhost:**/.
Here is what I did an working example
With regards, Angelina Jolie
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
1 Post
Re: How to sign in with Facebook account in an ASP.NET MVC project?
Jan 23, 2019 06:46 AM|moiyd|LINK
Dears
I had the same exact issue and this is what I have done to make it work. In the Nuget Manager, check below packages.
Thanks, @Angie Xu - MSFT for the hint.
BR, Moiyd