mardi 23 août 2016

Authenticate user with external url, Ember Simple Auth after callback with token

I use an external service for authentication Stamplay ..

To authenticate with username and password, I have to make a post in ${config.host}/auth/v1/local/login The callback for this post contain the token, so I created a custom authenticator to handle it

Custom Authenticator

export default Base.extend({
  tokenEndpoint: `${config.host}/auth/v1/local/login`,

  // ... Omited 

  authenticate(options) {
    return new Ember.RSVP.Promise((resolve, reject) => {
      Ember.$.ajax({
        url: this.tokenEndpoint,
        type: 'POST',
        data: JSON.stringify({
          email: options.email,
          password: options.password
        }),
        contentType: 'application/json;charset=utf-8',
        dataType: 'json'
      }).then(function (response, status, xhr) {
        Ember.run(function () {
          resolve({
            token: xhr.getResponseHeader('x-stamplay-jwt')
          });
        });
      }, function (xhr) {
        Ember.run(function () {
          reject(xhr.responseJSON.error);
        });
      });
    });
  },

  invalidate(data) {
    return Ember.RSVP.Promise.resolve(data);
  }
});

And everything works fine.. but ...

My problem

For social logins, I need to redirect the user to http://ift.tt/2bgjIWF

EXTERNAL_SERVICE can be.. github, twitter, facebook...

Then, the user is redirect to service page, and after login, the callback will be http://ift.tt/2bCzMQZ

So, how can I capture the token and login the user with this token?




Aucun commentaire:

Enregistrer un commentaire