Ember Simple Auth with external url authentication and callback with token


#1

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 https://MYAPP.stamplayapp.com/auth/v1/EXTERNAL_SERVICE/connect

EXTERNAL_SERVICE can be… github, twitter, facebook…

Then, the user is redirect to service page, and after login, the callback will be http://myapp.com/callback?jwt=XYZ

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


#2

Hi @ridermansb, thanks for reaching out. I noticed that you cross-posted this question to Stack Overflow, which is indeed the correct place to ask these sort of questions. While we don’t monitor Discuss for questions, there are several people over at Stack Overflow trying to answer questions, so you’re more likely to get help.

We would also like to keep the Learning category more focused on the Learning resources (tutorial, guides, API documentation) themselves, and on the meta discussion of learning Ember.

Good luck with your question!


Learning to nest route correctly
#3

Hi @locks… ok thanks.


#4

If you want to respond, please go to the Stack Overflow question question :slight_smile: