Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add oauth support #10

wants to merge 3 commits into


None yet
2 participants

jeremymarc commented Mar 22, 2012

No description provided.


dgeb commented Mar 22, 2012

Thanks for the PR. I appreciate where you're going with this, and I like how you've consolidated some ajax() code.

However, I don't want to place specific oauth logic (or tokens) directly in Ember.Resource or Ember.ResourceController. I'd rather provide a more flexible method for preparing ajax() params that could be used for more than just oauth.

For instance, Ember.Resource and Ember.ResourceController could implement:

  _ajaxParams: function(params) {
    params.url = this._resourceUrl();
    params.dataType = 'json';

  _ajax: function(params) {
    return jQuery.ajax(this._ajaxParams(params)); 

In your own app, you could then add oauth support via a mixin, like:

  YourApp.oauthToken = 'xyz';

  var OauthSupport = Ember.Mixin.create({
    _ajaxParams: function(params) {
      this._super(params); // add default params

      params.beforeSend = function (xhr, settings) {
        xhr.withCredentials = true;
        xhr.setRequestHeader('Authorization', 'Bearer ' + YourApp.oauthToken);


What do you think? Will this meet your needs? If so, do you want to revise your PR? If not, I'll work on this soon.


jeremymarc commented Mar 22, 2012

Good idea, I will do a new push in few minutes.

@dgeb dgeb closed this in b4abc4e Mar 22, 2012


dgeb commented Mar 22, 2012

@j075m - I've merged your changes and then refactored everything into a new mixin: Ember.ResourceAdapter. I've included notes on using this for oauth in the README. Thanks for your help :)


jeremymarc commented Mar 22, 2012

you're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment