0

I want to call a firebase auth function (which is in Javascript) from my controller and I want the returned token back in my controller, but I do not know how to proceed.

I know how to post ajax request to controller and get data back, however I don't know how to make a request the other way around.

I would be thankful if you can put me and other future users in right direction.

Randy
  • 9,419
  • 5
  • 39
  • 56
StealthTrails
  • 2,281
  • 8
  • 43
  • 67
  • PHP cannot call to Javascript. See http://stackoverflow.com/a/13840431/476. What you want is a PHP API to talk to Firebase, if such a thing is possible. – deceze Jun 17 '16 at 10:41

2 Answers2

7

This is not going to work.

You know a webserver is always supposed to be online. That way, you can always make a request.

A client-side (user), does not need, and isn't always online. If they close the browser window, you can't interact with them anymore. The server would have a hard time checking what user just went down, out of the thousands of users you have.

Making a call to a webserver is possible, but making a call to a client is not.

There are, next to that reason, security issues if you would be able to make a request to the client-side.

What you should probably do, is make a seperate request for the authentication token from Javascript, make Laravel call the Firebase AUTH server and then return the token it received.


update

It is possible to make requests to a client using HTTP2, by using server-push. To do that properly, especially with an authentication token, you will need some experience in building webservices and security.

Randy
  • 9,419
  • 5
  • 39
  • 56
3

PHP is a server side language and Javascript is client side. You cannot javascript on server and vice-versa. If you just need to generate JWT token, there are PHP libraries available for that already. But if you really want to execute javascript on server, that I think is not the case, you'll have to use nodejs

Rahul M
  • 1,498
  • 12
  • 19