mardi 1 septembre 2015

Torii provider name from adapter?

I have a Torii adapter that is posting my e.g. Facebook and Twitter authorization tokens back to my API to establish sessions. In the open() method of my adapter, I'd like to know the name of the provider to write some logic around how to handle the different types of providers. For example:

// app/torii-adapters/application.js
export default Ember.Object.extend({
  open(authorization) {
    if (this.provider.name === 'facebook-connect') {
      var provider = 'facebook';
      // Facebook specific logic
      var data = { ... };
    }
    else if (this.provider.name === 'twitter-oauth2') {
      var provider = 'twitter';
      // Twitter specific logic
      var data = { ... };
    }
    else {
      throw new Error(`Unable to handle unknown provider: ${this.provider.name}`);
    }

    return POST(`/api/auth/${provider}`, data);
  }
}

But, of course, this.provider.name is not correct. Is there a way to get the name of the provider used from inside an adapter method? Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire