import Ember from 'ember';
import Base from 'simple-auth/authenticators/base';
import config from 'ttz/config/environment';

export default Base.extend({
  torii: null,

  restore(data) {
    return Ember.RSVP.resolve(data);
  },

  authenticate(state) {
    if (config.environment !== 'production') {
      return Ember.RSVP.resolve({
        accessToken: 'token',
        scope: 'identify,read'
      });
    }

    return new Ember.RSVP.Promise((resolve, reject) => {
      this.torii.open('slack-oauth2', state).then(data => {
        return Ember.$.ajax({
          type: 'POST',
          url: '/api/tokens',
          data,
          dataType: 'json'
        });
      }).then(data => {
        resolve(data);
      }).catch(error => {
        reject(error);
      });
    });
  }
});

import Ember from 'ember';
import Base from 'simple-auth/authenticators/base';
import config from 'ttz/config/environment';

export default Base.extend({
  torii: null,

  restore(data) {
    return Ember.RSVP.resolve(data);
  },

  authenticate(state) {
    if (config.environment !== 'production') {
      return Ember.RSVP.resolve({
        accessToken: 'token',
        scope: 'identify,users:read'
      });
    }

    return new Ember.RSVP.Promise((resolve, reject) => {
      this.torii.open('slack-oauth2', state).then(data => {
        return Ember.$.ajax({
          type: 'POST',
          url: '/api/tokens',
          data,
          dataType: 'json'
        });
      }).then(data => {
        resolve(data);
      }).catch(error => {
        reject(error);
      });
    });
  }
});

Update to new more restrictive Slack OAuth2 scopes
Update to new more restrictive Slack OAuth2 scopes

All we need to read is users, so just ask for that.

https://api.slack.com/docs/oauth-scopes
