Angular2 vs Rails Api vs Facebook Auth - angularjs

I am using a rails api with devise gem to login to facebook. When i use a link from an html under the rails app directly to login. It works perfectly.
Now if i try to move to a client with angular2 and call the same route in the rails app. The problem occur in the redirect to facebook. I can hit the route cause i have already setuped "cors rack gem" but when behind the scene "devise gem" call the facebook api the origin for this call is null. I didn't find a way to get it work after 3h searching.
anyone setuped angular (1 or 2) with rails api and devise/omniauth?
the rails api and the angular app are under different domain

I endup using this gem for token based auth.
https://github.com/lynndylanhurley/devise_token_auth
I have removed devise totally from my gem file and i am using only "devise_token_auth" now.
You need to use a frontend library as for angular1
https://github.com/lynndylanhurley/ng-token-auth to call the api.
In my case i just used the demo from ng-token-auth, i extract the parameters from the call to register and used this parameters in a normal ajax call in my angular2 app => i was able to create a user.
normally devise_token_auth handle facebook proprely for ajax call (didn't try it yet)

Related

Can I use devise for authentication when I wanted to use Rails as a api only and React as a front end framework

I have a research task to do. I want to use Ruby on Rails as a api only application and React.Js as a front end framework. I have just started researching about it but I cant find any video/article that is using react-rails combo and devise as authentication. Is it possible to use devise for this combo or I have to do authentication all manual way using sessions and sending authorization token with every request from react.
hope this article helps. I used it for a group project and it worked.

How to implement mailing server with Next.js?

I am pretty new to Next.js and I want to implement a mailing feature for a contact form which I have on the site. Since Next.js is SSR, if we need to use a mailer I wonder: do we still need to have a separate backend environment where we then need to install the mailer (for example Node.js and Nodemailer) or we can install the mailer (for example Nodemailer) directly into the Next.js setup?
I know there is an option for having separate Node.js server, proving an API endpoint and using this endpoint for triggering the method where we will send emails (and probably send all the values from the contact form as a parameters in the endpoint), but I wonder if the Next.js allows direct implementation of a mailer nested directly into it's setup.
Next.js allows for creating custom API routes right within the project.
Here are the Docs:
https://nextjs.org/docs/api-routes/introduction
You need to create files in pages/api and the endpoint will be mapped to /api/*

How to request a Node.js code execution on the client side?

I have an Ionic Framework app (v1) and a Node.js file that executes some functions to a credit-card API I'm using. I've been testing the execution of the node file with the following command on terminal:
$ node file.js
And it works perfectly with my local machine. The problem is that I'll use my app for production soon, so how can I run this server-side code after a button click event in my front-end app ? Do I need to store this node file in the server and access it with angular http service ? How can I trigger the execution remotely?
I'm currently using Firebase as my back-end.
I've been struggling with this for days and I'm pretty new to Node.js. Please help me.
In terms of architecture and best practices, I recommend you to create an NodeJS API application and your Ionic app will make request to this API. You need to define route(s) to your NodeJS app, put it in production to provide Ionic app to send requests to its route(s).
As you sad that is a simple function, look at Express that is a NodeJS framework. The routing guide shows how to create a simple route using this framework.
To summarize, your Ionic app will send requests to NodeJS API route and this route will execute some functions to your credit card API.

Spring vs Angular js - Rest URLs getting exposed

I have a backend REST app. I'm presently developing the frontend app. Now i have a confusion as to how to setup the frontend app.
Case 1 - Plan to use Spring and have a frontend controller layer that takes care of calling the REST services. But i need to have models and POJOs setup same as in the backend to parse the JSON response. This seems like a overload on frontend. How to go around about this?
Case 2 - Plan to use Angular.js. Then i need to have all my REST URLs in the controller.js which is completely accessible for anyone. That way im totally exposing my REST domain, URL and request format. Is it not a security threat? How to go around about this?
Can you please tell me which case is better and secure and how to resolve the problem attached with it?
Secure your REST endpoints using a scheme like OpenId or OAuth or something else. Spring and numerous other web app frameworks have components to help with such authentication.
AngularJS is a client side framework. You can use Angular along with Spring. They are not mutually exclusive.
Finally, any http request (including RESTful http requests) invoked on a client is easily accessed simply by viewing the network traffic. Chrome, Firefox, along with other browsers provide tools, out of the box, that make this very easy to do. All the more reason to secure those REST endpoints.

Accessing google api's with Sencha 2

I want to access google places api with Sencha 2. I am using Ajax but I am getting cross origin request error (Testing in Chrome browser).
I cannot use jsonp as google api does not support response with callback parameter.
Does Sencha 2 provide any API to achieve this or do I have to route the response of api through my server?
Thanks
Found Google provides JS library to access the same places API.
http://code.google.com/apis/maps/documentation/javascript/places.html
It works perfectly now without the need to have ajax calls.
Thanks

Resources