Skip to content

Commit

Permalink
Support deep session object in token authenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadilla committed Feb 21, 2015
1 parent 7808d37 commit c2efe97
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions addon/authenticators/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ export default Base.extend({
@return {Ember.RSVP.Promise} A promise that when it resolves results in the session being authenticated
*/
restore: function(properties) {
var _this = this;
var _this = this,
propertiesObject = Ember.Object.create(properties);

return new Ember.RSVP.Promise(function(resolve, reject) {
if (!Ember.isEmpty(properties[_this.tokenPropertyName])) {
if (!Ember.isEmpty(propertiesObject.get(_this.tokenPropertyName))) {
resolve(properties);
} else {
reject();
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/authenticators/token-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,34 @@ test('#restore resolves with the correct data', function() {
});
});

test('#restore resolves custom token with the correct data', function() {
Configuration.tokenPropertyName = 'user.data.token';

App.authenticator = Token.create();

var properties = {
user: {
data: {
token: 'secret token!'
}
}
};

App.server.respondWith('POST', '/api-token-auth/', [
201,
{
'Content-Type': 'application/json'
},
'{ "token": "secret token!" }'
]);

Ember.run(function() {
App.authenticator.restore(properties).then(function(content) {
deepEqual(content, properties);
});
});
});

test('#authenticate sends an AJAX request to the sign in endpoint', function() {
sinon.spy(Ember.$, 'ajax');

Expand Down

0 comments on commit c2efe97

Please sign in to comment.