How do I create a value for Facebook:VerifyToken:User in a Facebook application using ASP.NET MVC 4 with Web Tools 2012.2? - facebook

I am using ASP.NET and Web Tools 2012.2. I created a Facebook application under ASP.NET MVC 4 Web Application and target of .Net Framework 4.5. I can create an AppId and AppSecret
through https://developers.facebook.com/apps but the application requests a value for Facebook:VerifyToken:User. Exactly how do I create one and get the application to work?

The "Facebook:VerifyToken:User" setting in the project template is optional and is used in the UserRealtimeUpdateController. You only need to set this when your application want to support Facebook Realtime Updates. See this link for more information about the realtime updates: https://developers.facebook.com/docs/reference/api/realtime/
The VerifyToken is set by you when you create a realtime update subscription.
Hope this helps,
Yao

You can use either DotNetOpenAuth or the Facebook C# SDK to authenticate against Facebook and request an access token. Take a look at the FacebookClient in DotNetOpenAuth, I've successfully used this to request an access token. You will need to pass the right scope parameter across for the permissions you need. Could you elaborate on how your app needs to interact with Facebook?

I gave a value for the Facebook:AppNamespace setting (which is supposedly optional according to the literature that I have read as well as stating so on the Facebook form). Once I did this, the problem went away.

Related

Has anyone actually got ASP.NET MVC 5 Identity Facebook logins to work out of the box? (loginInfo always returns null)

Using Visual Studio 2013 Update 5, I have created a boilerplate MVC 5 application with Individual User Accounts auth option selected, and I have been trying to implement social logins using the template code, but have been unsuccessful.
I have ensured all NuGet packages are up to date, and the code is using MVC 5.2.3; Owin 3.0.1; AspNet.Identity 2.0.0.
I can get everything working fine, including authenticator apps using OtpSharp, but the Facebook login is just not working whatever I try.
I have created the Facebook App, set all the relevant options on that and set the AppId and AppSecret in my Startup.Auth.cs file.
When I try to login with Facebook, the MVC site redirects me to Facebook, which prompts me with the auth screen for the app. I click OK and accept this then I am redirected back to the MVC app. If I check the authorised apps under my Facebook account, my app is listed and shows that it has granted permission to the app to retrieve email address.
The callback works fine but when it hits ExternalLoginCallback and in particular:
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync()
loginInfo always returns null.
Looking at the Request it shows an error of access_denied:
https://localhost:44301/Account/ExternalLoginCallback?ReturnUrl=%2Fmanage&error=access_denied
I have read pretty much every blog post and SO question on this error and whilst most of them are helpful, most are also out of date and not relevant.
It would seem that something is missing from the templated project, or something has changed elsewhere as no matter which tutorial I read, and options I set, the result is the same.
I have tried this internally on a dev machine running IIS Express and externally on a hosted machine running IIS 7.5 too and the results are the same.
I've even decompiled the Microsoft.Owin.Security.Facebook library to see where that particular section of the querystring is set to no help.
If I had any hair I'd have pulled it all out by now.
I'll take any suggestions. Can anyone help?
Facebook loves to make things difficult. Access_denied sounds like they are blocking you on purpose. Check your developer dashboard and the accounts authorized to test your app while its in development mode. The email permission is approved by default, so that isn't your issue.
Make sure the account you are testing with is added here:
If that doesnt solve it, make sure you have the correct app domains (testing and live) listed in the domain section here:
I had the exact same issue. No matter what I did the facebook would show the login, get permissions and then return back to the Login page instead of the Email confirmation page.
Using Fiddler Facebook would invoke "http://localhost:1234/signin-facebook&code=SOME_SECRET_CODE_HERE", and then my application's controller would invoke "http://localhost:1234/ExternalLoginCallback?error=access_denied". I was sure Facebook is refusing the access. It was only after implementing a Facebook Javascript SDK Sample, I realised I could successfully login and also view FB scopes!
My Dev environment
MVC 5 application
Visual Studio 2013 Community edition Update 5
Microsoft.OWIN v2.2.1
Microsoft.OWIN.Security.Facebook v3.0.1
Finally I found a YouTube Video by ProCoder which mentioned to put the correct path in the Valid OAuth redirect URIs as http://localhost:1234/signin-facebook and it worked. If you haven't already added, you will need to add Facebook Login product to your Facebook app.
I also set App Domain to localhost and Site URL to http://localhost:1234/
I have added 127.0.0.1 and MY.EXTERNAL.PUBLIC.IP to the Server IP Whitelist Under Security in the Advanced Settings option of the Facebook app.
All these settings I replicated in a new MVC 5 application and it worked like a charm.
update the package Owin.Security.Facebook 3.0.1 to 3.1.0
It works for me

Web API FB OAuth? How would to go about implementing it in a SPA application?

Documentation on the net seems to be VERY scarce. The only option I can think of at the moment
is to have my SPA app break convention and to have the (initial) logged out page be different to the logged in one (eg my app).
My app is built using Durandal 2.0.0.
In one of my OAuth tests app's I've managed to implement this link successfully. But as Durandal does not work in the same way (Server-side controller, & razor views), I'm thoroughly confused in how to achieve what I want to.
I'd like to have my app remain a single page app. But I've got little to no experience with the OAuth SDK
My only requirement is that the user log into my app using his FB account.
I've had an initial stab at this using the FB java script API, and got it working, but after discussions with another developer this side, it doesn't seem like the purpose of the java script API is to facilitate secure application login's? As the way we had it, would allow any user to pass a valid fb userId, then he would be logged into our app. :/
How would I go about achieving this process flow in a Durandal/Web API Single Page App?
User logs in using fb ->
then on the server we get his fb userId ->
retrieve our internal appID
I'm not asking for a complete answer/for someone to do my work....
But any documentation to get me started/less confused would be greatly appreciated.
Here is a sample project which demonstrates how to use OAuth with Durandal and Web API:
DurandalAuth.
However there are some modifications in viewmodels needed, since router changed in Durandal 2.0.0.

Is there a best practices/example solution for using the Fb C# SDK v6 on ASP.NET MVC?

I'm currently using the Fb C# SDK v5, works like a champ. Migrating to v6 is proving more challenging than I had anticipated.
So, I decided to rewrite the auth code from scratch. Is this the bare minimum needed to authenticate a user?
Use the Fb js sdk to set the appId, subscribe to the auth event
Subscribe to the Fb.UI auth event, pass the access token to the server
Once the server has the access token, query the graph
In v5 I was doing this in an OnActionExecuting override, checking against an active session (if it wasn't active, I'd re-auth via Fb). I just can't seem to get it to work like that on v6.
Is there a best practices, or example solution, for using the Fb C# SDK v6 on ASP.NET MVC? I'd like to make sure I'm doing this right. I've found a couple resources, but they don't look like they're specifically for ASP.NET MVC:
Writing your First Facebook Application (v6)
Getting Started with the Facebook C# SDK for ASP.NET
Thanks!
I've been searching for the same and now I found a sample for MVC and Facebook v6.0 api at github:
https://github.com/facebook-csharp-sdk/facebook-aspnet-sample

How to register a Facebook Application via API/PHP?

I want to provide a system that automatically registers/creates Facebook Applications for its users. Unfortunately I did not find a way to register a new Application via API.
I know that this is possible, because I saw this e.g. here:
http://apps.facebook.com/applicationbuilderl/Setup/New.aspx
How can I register a new Facebook Application (I need to get back AppId, Secret and Key), with a form to fill out, on my website or within my facebook app?
Thanks a lot,
Sebastian
This is possible using the old Javascript SDK:
http://developers.facebook.com/docs/reference/oldjavascript/FB.Connect.createApplication
As the name of the SDK lets assume this is all deprecated stuff and will not be longer supported and/or removed by facebook.

Get oAuth 2.0 access token from asp.net webforms iframe canvas application

The question says it all:
How can I get an access token to use on graph api calls from a asp.net webforms 4.0 iframe canvas app.
My canvas application has been configured to enable the OAuth 2.0 for Canvas (beta) among other things.
This means I am getting the signed_request parameter on my iframe which I am successfully reading.
From the oficial documentation on canvas authentication
The signed_request parameter is the concatenation of a HMAC SHA-256 signature string, a period (.), and a base64url encoded JSON object.
There is a php code in the documentation which decodes the signed_request but I haven't been able to implement it propertly in C# partly beacuse to be honest I prefer not to reinvet the wheel but to use someone else code that has been already tested.
This is where my quest for a good C# Facebook SDK started again (since facebook changes everything every few months librarys get usually obsolete).
I have used the codeplex's Facebook Developer Toolkit in the past but it seems to be getting outdated ans the lastest stable release is very old (in facebook API time)
Some months ago used the Oficial Facebook C# SDK from GitHub but it lacks completly the authentication support.
Now I have found on Nuget and really liked the Facebook C# SDK from Nathan Totten who is one of the top Facebook Experts here in StackOverflow.
If you Nathan read this (or anyone that also uses this sdk), how can I use this SDK to get an access token to use in my canvas app.
Anyway if there is a better way to get a token, maybe with the Javascript library please let me ( and the people who wonder the same as me ) know.
Hey, Carlos. So to get the access token, you just need to do the following after the user has authenticated:
FacebookApp app = new FacebookApp();
var accessToken = app.Session.AccessToken;
Also, see my answer to this question: facebook-C#-sdk MVC "Hello World" app - how to get access token?
Hopefully that helps, otherwise let me know if you have any other questions.