Facebook authentication in a new browser instance Asp.net MVC - asp.net-mvc

I have an Asp.Net MVC 4 app an i have a feature in which the app can post to user's wall.
Its working fine, but currently the url
https://www.facebook.com/dialog/oauth?client_id=XXXXX&redirect_uri=http://localhost:xxxxxx/&scope=publish_stream
redirects to facebook page , authenticates ,post the message and redirects back to my app.
Is it possible to open the facebook authentication page in a new browser instance and somehow close the browser instance once the message is posted ?
Thanks !

Not sure if this covers what you want to achieve but by using Facebook Feed Dialog, you can set display parameter to appropriate value (e.g. popup) and let the user publish a story to a timeline.

Related

How to return back to the application after webview?

The flow of application requires user to go to a webpage and update few details after which the user need to come back with id that website has provided.
Working senario:
User logs in application
clicks button goes to the website update few details
stays in the Webview for the website
Required Senario:
Should come back to the app with the id that website provided
The flow of the app is something similar to google Oauth where the user clicks the google button to authenticate google to use the google account.
You can show the web page in a WKWebView. Assuming you also are coding the web page you can also use evaluateJavaScript(:completionHandler:) to figure out when the website is done, grab the result, and dimiss the WKWebView. Alternatively you can intercept the success navigation with the WKNAvigationDelegate method webView(:didStartProvisionalNavigation:) and then grab whatever info you need from the server.

Build web page request in Objective C

I'm building a native application. The app has an embedded webview (UIWebView) pointing to a social website. To be able to use the website inside the app, user has to log in by the webview (username/password) and then he can continue use the site with saved cookies. Normally, the cookies expire after two days. After that, the user has to re-login by the webview.
Now suppose I know username and password of the user and I would like to make the user login automatically with this account when the cookie expires. How can I do that?
I tried to simulate the Login action when I click on Login button on web page, but not successful.By using "Inspect Element" of Chrome, I can see Chrome makes a "Post" request to an URL with some parameters. However, the request doesn't get successful (I use REST client for testing).
Finally I found out the solution. I didn't build requests anymore. I used javascript to set text fields and make "click" action on the webview. Done.

Does Twitter has a static page for OAuth redirects?

I'm developing a desktop application which is supposed to allow users to login via Twitter.
There seems to be 2 ways to do so, that differ in a way oauth_verifier is returned to the application.
The first one is for web applications and oauth_verifier is returned as a url query parameter when redirecting user back to redirect_url.
The second one is using a PIN displayed to the user, which user enters to the app.
Now Facebook, for example, has a page facebook.com/connect/login_success.html , where FB can redirect a user with ouath_verifier as a query param (e.g. facebook.com/connect/login_success.html?code=<token>. Then I can read that param back from the browser's location field (I'm using an embedded browser).
So, is such a workflow possible with Twitter? Does it have a static page, where it can redirect user with oauth_verifier ?
I haven't been able to find such a page in Twitter's API docs, so I ended up using the main page twitter.com for the redirect. Everything works fine.

Accesstoken not available after reopening website

I have a MVC 3 website with the Facebook C# SDK.
Now i'm redoing the facebook integration in a clean MVC 4 application with the new version 6 of the sdk. So I used the gettings started help page on the sdk website. http://csharpsdk.org/docs/web/getting-started
I've followed the tutorial and changed only one part of the tutorial. The thing that I changed was that I call an Controller Action because the ashx was fired but wasn't allowed to set the accesstoken in the Session object. The Session was null.
Now when I start the website for the first time (used Chrome because IE won't work by default. The tutorial explains why.), I see the login button.
When I press the login button, I get the authorize page of facebook that asks that my app wants to connect to my facebook account. When I submit, the MVC action in the controller gets fired and the given accesstoken is stored in the session.
After that I can access my own information.
When I close Visual Studio (IIS express is closed with it) and restart the website, the login button is changed to my account with picture that says that I use the app that is connected. After that I navigate back to the page with my own information and get a nullreferenceexception on the session that gets the accesstoken. Why is that? Why is the user logged in but the action that stores the accesstoken isn't fired the second time that I open the website (new session).
Shouldn't I set the app secret somewhere? I have set the AppId in the javascript following the tutorial.
Thanks.
Per Facebook your user is logged into your app, but since you restarted your Cassini web server, your "session" is gone/lost/deleted.
Check your session to ensure you have a valid token, in session, if not redirect the user to your login code.

Deep link into a Facebook canvas app

I am embedding a Facebook app https://example.com into the Facebook app canvas so that it is available at https://apps.facebook.com/EXAMPLE . My application sends notification emails that contain links like https://example.com/messages/123 and that should open the page embedded into the Facebook canvas. How do I achieve this? My current thoughts:
User opens https://example.com/messages/123
Application checks for signed_request parameter
Application redirects user to https://apps.facebook.com/EXAMPLE/?requested_page=/messages/123
Application checks for requested_page parameter and redirects to this page
User sees https://example.com/messages/123 URL and is embedded into canvas
Is there a better pattern out there to get this working?
My final working solution (with Ruby on Rails)
User opens https://example.com/messages/123
Application checks on client-side if app is embedded in canvas:
if(window == top){
top.location = "https://apps.facebook.com/#{Settings.facebook.app_id}#{request.fullpath}";
}
User is redirected to https://apps.facebook.com/EXAMPLE/messages/123
Application middleware converts POST into GET if signed_request is present (code and idea borrowed from https://github.com/dekart/facebooker2/blob/master/lib/facebooker2/rack/post_canvas.rb)
Application parses signed_request with fb_graph gem
FbGraph::Auth.new(app_id, app_secret, :signed_request => params[:signed_request])
I'd just update the link to point to http://apps.facebook/example/messages/123 off the start.
When you check for authentication just set the redirect after authorization/login to the same page.
Redirecting a user around multiple pages for no reason is just not a good practice.

Resources