How can I implement the facebook authentication in a MEAN application preventing CORS problems? - angularjs

I'm implementing an application using the full MEAN stack.
I created a login page to signup with facebook to be able to show a profile page. But I discovered some problems. For this reason, I created a smaller version of my webapp, maintaining the same project structure.
The complete code, executable (only replacing "client id" and "secret") with "npm install" and after "nodemon" is available here: https://github.com/Ks89/MEAN-OAuth_Example
If I'll call (with a browser) the rest API that I created to login with facebook at "http://localhost:3000/api/auth/facebook", everything will be ok!
But if I'll want to do the same thing, clicking on the "Login" button, I'll receive the error as in figure:
I know that the problem is related to CORS, but how can I'll fix this in my application, maintaining the same project structure?
I don't want to put the "rest path" inside the HTML. I tried for many days different solutions without success.
If you want, experiment directly on my application that I created exactly to write this question ;).
If really necessary, I'll able to post the entire source code here, but I prefer an organized and executable code into a repository for this particular question.
Please, give me some ideas and hopefully a solution, because I'm really blocked.

The example routes from the passport-facebook repo are intended for multipage apps, not ajax requests. If you look at what those routes are doing, /auth/facebook is just a redirect to Facebook where the user is expected to log in if necessary and authorize your application. When you make that same request from angular, it follows the redirect and tries to load the Facebook page, but the browser blocks you as your console screenshot shows. CORS would be relevant if Facebook wanted to allow you to request their login form across origins, but they don't because that would basically make you a phisher.
It looks like you're trying to handle authentication without leaving the page, but at some point you're going to need the user to leave your site and be redirected to Facebook in order to complete the OAuth flow. You can either open a pop-up containing the Facebook OAuth dialog (it looks like this is what the Facebook JavaScript SDK does by default) or just use your app's current tab with something as simple as <a ng-href="{{facebookOauthUrl}}">Log in with Facebook</a>.

Related

Opening new default browser window in plain React on a Mobile while using Facebook browser

Folks,
We are in a unique situation here. Our React site integrates with Signicat for identity solution. Most of our user base comes from Facebook i.e. they use the Facebook app, look at our posts and click on links we post which redirect to certain sections in our website which require identification.
So an example link posted on Facebook group https://example.com/en/startpage-in-english/ is converted into https://l.facebook.com/l.php?u=https%3A%2F%2Fexample.com%2Fen%2Fstartpage-in-english%2F%3Ffbclid%3DIwAR3loYqYOvom5k8_mOww89p5tun5H9HqIIKE1ebwwCcB3PD4jzxpTVyZGCk&h=AT1E3p1ejYWH9l2KhUo8D_RVjl_EzKBat4woeMHgRv7yXpT9Y-EZoBcK26sQtjjBBwAQt7Pt83a-i_k5JCGuvOBWfgB9pZ7Uv8LnDlyphNKc1Og0nl6QIqWd_nFEAva3OWN-PZ3byqsU7K0I5A&__tn__=-UK-R&c[0]=AT0-5n51iPMlSYghORXW8qxYXJQEejQTAhfiDQ3P3DK_ZTZM3GWbN4zXYKf-nyD_hWJdxQccenDp-5VgphfWuD6ZQ0ikeXq4lv4bjLbSJVFP9k4IxeMBT5mDa9jNdYnYlNs-DkXOM-LiPhhl-Obra9CAbtvihe-G7-8. When users click on the link, Facebook by default opens the link in its own Facebook browser. The subsequent steps in our portal need the user to identify himself and when the identification is completed and in the final step the request to Signicat hangs forever.
We identified that this issue is only happening with Facebook browser and hence one of the workarounds was to Open the default browser with the link to our website.
Note that:
a. this is not a React-Native app, our website is built using plain React hence the WebView solution does not work.
b. Facebook browser suppresses "window.open" with "newwindow" call and simply displays the site in the same Facebook browser instance.
So bottom line is, we need a way to Open the default OS Browser from Facebook App/Browser with the link to our site. Hope somebody can help!
Thanks in advance...
SG

React PayPal Payment process checkout

I'm new to the react web app, I trying to create cart payment checkout process. All the modules PayPal button open in same page with POPUP. I want to redirect from my site to the PayPal site and return back to my site. Currently i'm using the below example. Is there any module to create order and redirect.
https://www.npmjs.com/package/react-paypal-button-v2
Why do you want to redirect away from your site? That's how things were done 5+ years ago.
It's much better to keep your site loaded and present in the background and show payers an in-context approval experience, instead of redirecting them over to a new and possibly unfamiliar login page.
You are asking for how to do something you shouldn't even be trying to do, and which will result in an inferior buyer experience and fewer completed checkouts, which is the opposite of what you should want.
But since you ask, the way to do it is not not use the PayPal JavaScript SDK button. Just use the /v2/checkout/orders REST API to create an order and receive an approval_url, which you can redirect to with a static "Checkout with PayPal" button from, say, https://www.paypal.com/us/webapps/mpp/logos-buttons
Again, full page redirects are an old integration method that give a poor buyer experience and you shouldn't use this method.

Oracle ADF - Redirect link is not working

I am developing a simple application using ADF comes with basic CRUD operations (create, read, update, delete). In this case, as you can see, I have dragged a link to the 1st column which is highlighted in yellow.
So whenever I deploy it and click that, it is supposed to redirect me to the Edit page where client will allow to make commit:
I did make sure the Action of link is associated with the Edit page (as highlighted in yellow above). However, the link wouldn't redirect me anywhere, no response.This is the unbounded task flow:
Okay so I have found out the solution. Due to the default setting, the application will be deployed on IE and this message will prompt out. As you can see, the message is mentioning about browser's compatibility. My IE is version 11.6, I'm not sure what's the issue here since my IE is kinda latest version but this message still pops out and affects the redirect link from working. However, simply copy the application URL to Google Chrome and run should fix this issue. Hope this helps in future.
If the two pages in the Unbounded Task Flow, then Add WildCard Control Flow Rule
and connect the two pages with the WildCard.
Or you can use the Popup instead of opening a new page for edit

AngularJS application problems appearance in Google search

I have a personal project which consumes my free time and effort for about a year without significant profit. I have problems with it appearance in Google and would really appreciate to get help here.
This project (http://yuppi.com.ua - similar to craiglist in US) is WEB-based AngularJS 1.2 application that uses PHP rest API hosted on GoDaddy. And in order to make this application popular it have to be very visible in internet and very searchable in Google and users have to be able to share pages via social networks or skype.
According to Google specification, google crawlers doesn't run javascript to get content of a web page before index, so I've added _escaped_fragment_ page that displays content of web page without javascript. For example:
Page: http://yuppi.com.ua/#!/items/sub/18/_
Dirty : yuppi.com.ua/?_escaped_fragment_=/items/sub/18/_
This dirty page will be redirected here where google will see content.
http://yuppi.com.ua/server/crawler_proxy/routee.php?path=/items/sub/18/
So basically I have two versions on HTML file for that page. One version is the one that available to users, which has styles, a lot more HTML tags etc. And the second is the version for Google crawler - very light-weight without any styles. And I am expecting to see clean link to my site in Google, not dirty.
So, If to search all links to a web site in Google you will see that one of the links displays it's "dirty" state.
Another problem is sharing links in Skype.
When I send a link to someone, I am expecting that this link will be transformed to thumbnail image but it is not happens. Instead I see ungly link to my web site.
Please help me to understand how to make happy everyone: users, google crawler, GoDaddy and me.
I was encountering the same problems last year with a big project and we ended to use : https://prerender.io/.
It's a prerendering system that work with a phantomjs browser to detect bot request and render a full html template. It does also instanciate a cache service to not render again a template that haven't change.
Hope it help's.

Authentication routing problems with angular-material-fullstack

Having scaffolded an angular-material-fullstack project using the yeoman generator, I have run into a problem with its verification straightaway.
It seems that there's a bug from the outset, because when clicking Signup below, the app does not redirect to the signup page as it should, rather it stays on the log in page:
Even when explicitly typed in to the address bar (localhost:9000/signup), I still get relocated to /login.
I can get to the 'main' section of the app without logging in, however, the app gets confused by this, and doesn't know what to display for the menu buttons in the main menu (should be login and sign out):
Previously in this environment the app was working like a dream. This time I opted for uiRouter rather than ngRoute, and I'm wondering if, for some reason, this may be the cause of the problem. Any help warmly appreciated.

Resources