lynndylanhurley / ng-token-auth

Token based authentication module for angular.js.
Do What The F*ck You Want To Public License
1.8k stars 234 forks source link

Problem with facebook authentication #67

Closed ghost closed 9 years ago

ghost commented 9 years ago

I have a problem with when I want to log in with facebook. The registration with facebook worked and user was created.

The login call opens a new window with "Redirecting..." and url "http://localhost:3000/api/auth/facebook/callback#_=_"

What do I miss?

My controller looks like this:

module.controller('FacebookCtrl', ['$auth', '$scope', '$state',
  function($auth, $scope, $state) {
    $scope.authFacebook = function() {
      $auth.authenticate('facebook')
        .then(function(response) {
          $state.go('dashboard');
        })
        .catch(function(error) {
          console.log('error: ', error)
          $scope.error = error.errors[0];
        });
    };
}]);
lynndylanhurley commented 9 years ago

The "Redirecting..." page exists to send authentication info from the OAuth provider back to the angular app. Once the values are sent (via postMessage), the window should close itself automatically.

There must be some kind of error that is preventing the window from sending messages.

Can you "View Source" on the "Redirecting..." page and post the results?

ghost commented 9 years ago

@lynndylanhurley - thank you. Please let me know if you need more.

<!DOCTYPE html>
<html>
  <head>
    <script>
      var usingExternalWindow = function() {
        var nav     = navigator.userAgent.toLowerCase(),
            ieLTE10 = (nav && nav.indexOf('msie') != -1),
            ie11    = !!navigator.userAgent.match(/Trident.*rv\:11\./);
        return !(ieLTE10 || ie11);
      }

      if (usingExternalWindow()) {
        window.addEventListener("message", function(ev) {
          if (ev.data === "requestCredentials") {
            ev.source.postMessage({
                "id": "162",
  "email": "EMAIL",
  "name": "NAME",
  "nickname": "",
  "image": "IMAGE",
  "provider": "facebook",
  "uid": "UID",
  "created_at": "2014-11-20 16:21:36 UTC",
  "updated_at": "2014-11-20 16:22:31 UTC",

"auth_token": "AUTH_TOKEN",
"message":    "deliverCredentials",
"client_id":  "CLIENT_ID",
"expiry":     "1417710151"

            }, '*');
            window.close();
          }
        });
      } else {
        window.location.href = "http://localhost:3000/#/login?client_id=lLD5t3HG2J3aA8LvUE-nkg&amp;expiry=1417710151&amp;token=d_cMFIMsOohZ6lE0Kc_HEw&amp;uid=10202974252489710";
      }
    </script>
  </head>
  <body>
    <pre>
      Redirecting...
    </pre>
  </body>
</html>
lynndylanhurley commented 9 years ago

This looks ok actually. Are you seeing any JS console errors on either this page or the angular app?

Also, which browser are you using?

ghost commented 9 years ago

@lynndylanhurley - I'm no longer able to produce the error, so I'm closing this issue. Sorry for the noise.

lynndylanhurley commented 9 years ago

Hey no problem! Glad everything worked out :smiley: