Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/grant-types/abstract-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function AbstractGrantType(options) {

AbstractGrantType.prototype.generateAccessToken = function(client, user, scope) {
if (this.model.generateAccessToken) {
return promisify(this.model.generateAccessToken, 3)(client, user, scope)
return promisify(this.model.generateAccessToken, 3).call(this.model, client, user, scope)
.then(function(accessToken) {
return accessToken || tokenUtil.generateRandomToken();
});
Expand All @@ -53,7 +53,7 @@ AbstractGrantType.prototype.generateAccessToken = function(client, user, scope)

AbstractGrantType.prototype.generateRefreshToken = function(client, user, scope) {
if (this.model.generateRefreshToken) {
return promisify(this.model.generateRefreshToken, 3)(client, user, scope)
return promisify(this.model.generateRefreshToken, 3).call(this.model, client, user, scope)
.then(function(refreshToken) {
return refreshToken || tokenUtil.generateRandomToken();
});
Expand Down Expand Up @@ -103,7 +103,7 @@ AbstractGrantType.prototype.getScope = function(request) {
*/
AbstractGrantType.prototype.validateScope = function(user, client, scope) {
if (this.model.validateScope) {
return promisify(this.model.validateScope, 3)(user, client, scope)
return promisify(this.model.validateScope, 3).call(this.model, user, client, scope)
.then(function (scope) {
if (!scope) {
throw new InvalidScopeError('Invalid scope: Requested scope is invalid');
Expand Down
6 changes: 3 additions & 3 deletions lib/grant-types/authorization-code-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ AuthorizationCodeGrantType.prototype.getAuthorizationCode = function(request, cl
if (!is.vschar(request.body.code)) {
throw new InvalidRequestError('Invalid parameter: `code`');
}
return promisify(this.model.getAuthorizationCode, 1)(request.body.code)
return promisify(this.model.getAuthorizationCode, 1).call(this.model, request.body.code)
.then(function(code) {
if (!code) {
throw new InvalidGrantError('Invalid grant: authorization code is invalid');
Expand Down Expand Up @@ -160,7 +160,7 @@ AuthorizationCodeGrantType.prototype.getAuthorizationCode = function(request, cl
*/

AuthorizationCodeGrantType.prototype.revokeAuthorizationCode = function(code) {
return promisify(this.model.revokeAuthorizationCode, 1)(code)
return promisify(this.model.revokeAuthorizationCode, 1).call(this.model, code)
.then(function(status) {
if (!status) {
throw new InvalidGrantError('Invalid grant: authorization code is invalid');
Expand Down Expand Up @@ -195,7 +195,7 @@ AuthorizationCodeGrantType.prototype.saveToken = function(user, client, authoriz
scope: scope
};

return promisify(this.model.saveToken, 3)(token, client, user);
return promisify(this.model.saveToken, 3).call(this.model, token, client, user);
});
};

Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/client-credentials-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ClientCredentialsGrantType.prototype.handle = function(request, client) {
*/

ClientCredentialsGrantType.prototype.getUserFromClient = function(client) {
return promisify(this.model.getUserFromClient, 1)(client)
return promisify(this.model.getUserFromClient, 1).call(this.model, client)
.then(function(user) {
if (!user) {
throw new InvalidGrantError('Invalid grant: user credentials are invalid');
Expand Down Expand Up @@ -100,7 +100,7 @@ ClientCredentialsGrantType.prototype.saveToken = function(user, client, scope) {
scope: scope
};

return promisify(this.model.saveToken, 3)(token, client, user);
return promisify(this.model.saveToken, 3).call(this.model, token, client, user);
});
};

Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/password-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ PasswordGrantType.prototype.getUser = function(request) {
throw new InvalidRequestError('Invalid parameter: `password`');
}

return promisify(this.model.getUser, 2)(request.body.username, request.body.password)
return promisify(this.model.getUser, 2).call(this.model, request.body.username, request.body.password)
.then(function(user) {
if (!user) {
throw new InvalidGrantError('Invalid grant: user credentials are invalid');
Expand Down Expand Up @@ -122,7 +122,7 @@ PasswordGrantType.prototype.saveToken = function(user, client, scope) {
scope: scope
};

return promisify(this.model.saveToken, 3)(token, client, user);
return promisify(this.model.saveToken, 3).call(this.model, token, client, user);
});
};

Expand Down
6 changes: 3 additions & 3 deletions lib/grant-types/refresh-token-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ RefreshTokenGrantType.prototype.getRefreshToken = function(request, client) {
throw new InvalidRequestError('Invalid parameter: `refresh_token`');
}

return promisify(this.model.getRefreshToken, 1)(request.body.refresh_token)
return promisify(this.model.getRefreshToken, 1).call(this.model, request.body.refresh_token)
.then(function(token) {
if (!token) {
throw new InvalidGrantError('Invalid grant: refresh token is invalid');
Expand Down Expand Up @@ -127,7 +127,7 @@ RefreshTokenGrantType.prototype.revokeToken = function(token) {
return Promise.resolve(token);
}

return promisify(this.model.revokeToken, 1)(token)
return promisify(this.model.revokeToken, 1).call(this.model, token)
.then(function(status) {
if (!status) {
throw new InvalidGrantError('Invalid grant: refresh token is invalid');
Expand Down Expand Up @@ -166,7 +166,7 @@ RefreshTokenGrantType.prototype.saveToken = function(user, client, scope) {
return token;
})
.then(function(token) {
return Promise.try(promisify(this.model.saveToken, 3), [token, client, user])
return promisify(this.model.saveToken, 3).call(this.model, token, client, user)
.then(function(savedToken) {
return savedToken;
});
Expand Down
4 changes: 2 additions & 2 deletions lib/handlers/authenticate-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ AuthenticateHandler.prototype.getTokenFromRequestBody = function(request) {
*/

AuthenticateHandler.prototype.getAccessToken = function(token) {
return promisify(this.model.getAccessToken, 1)(token)
return promisify(this.model.getAccessToken, 1).call(this.model, token)
.then(function(accessToken) {
if (!accessToken) {
throw new InvalidTokenError('Invalid token: access token is invalid');
Expand Down Expand Up @@ -232,7 +232,7 @@ AuthenticateHandler.prototype.validateAccessToken = function(accessToken) {
*/

AuthenticateHandler.prototype.verifyScope = function(accessToken) {
return promisify(this.model.verifyScope, 2)(accessToken, this.scope)
return promisify(this.model.verifyScope, 2).call(this.model, accessToken, this.scope)
.then(function(scope) {
if (!scope) {
throw new InsufficientScopeError('Insufficient scope: authorized scope is insufficient');
Expand Down
6 changes: 3 additions & 3 deletions lib/handlers/authorize-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ AuthorizeHandler.prototype.handle = function(request, response) {

AuthorizeHandler.prototype.generateAuthorizationCode = function(client, user, scope) {
if (this.model.generateAuthorizationCode) {
return promisify(this.model.generateAuthorizationCode)(client, user, scope);
return promisify(this.model.generateAuthorizationCode).call(this.model, client, user, scope);
}
return tokenUtil.generateRandomToken();
};
Expand Down Expand Up @@ -171,7 +171,7 @@ AuthorizeHandler.prototype.getClient = function(request) {
if (redirectUri && !is.uri(redirectUri)) {
throw new InvalidRequestError('Invalid request: `redirect_uri` is not a valid URI');
}
return promisify(this.model.getClient, 2)(clientId, null)
return promisify(this.model.getClient, 2).call(this.model, clientId, null)
.then(function(client) {
if (!client) {
throw new InvalidClientError('Invalid client: client credentials are invalid');
Expand Down Expand Up @@ -264,7 +264,7 @@ AuthorizeHandler.prototype.saveAuthorizationCode = function(authorizationCode, e
redirectUri: redirectUri,
scope: scope
};
return promisify(this.model.saveAuthorizationCode, 3)(code, client, user);
return promisify(this.model.saveAuthorizationCode, 3).call(this.model, code, client, user);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/token-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ TokenHandler.prototype.getClient = function(request, response) {
throw new InvalidRequestError('Invalid parameter: `client_secret`');
}

return promisify(this.model.getClient, 2)(credentials.clientId, credentials.clientSecret)
return promisify(this.model.getClient, 2).call(this.model, credentials.clientId, credentials.clientSecret)
.then(function(client) {
if (!client) {
throw new InvalidClientError('Invalid client: client is invalid');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"jshint": "2.9.4",
"mocha": "3.3.0",
"should": "11.2.1",
"sinon": "2.1.0"
"sinon": "2.3.2"
},
"license": "MIT",
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/grant-types/abstract-grant-type_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('AbstractGrantType', function() {
return handler.generateAccessToken()
.then(function() {
model.generateAccessToken.callCount.should.equal(1);
model.generateAccessToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand All @@ -38,6 +39,7 @@ describe('AbstractGrantType', function() {
return handler.generateRefreshToken()
.then(function() {
model.generateRefreshToken.callCount.should.equal(1);
model.generateRefreshToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down
3 changes: 3 additions & 0 deletions test/unit/grant-types/authorization-code-grant-type_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('AuthorizationCodeGrantType', function() {
model.getAuthorizationCode.callCount.should.equal(1);
model.getAuthorizationCode.firstCall.args.should.have.length(1);
model.getAuthorizationCode.firstCall.args[0].should.equal(12345);
model.getAuthorizationCode.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand All @@ -51,6 +52,7 @@ describe('AuthorizationCodeGrantType', function() {
model.revokeAuthorizationCode.callCount.should.equal(1);
model.revokeAuthorizationCode.firstCall.args.should.have.length(1);
model.revokeAuthorizationCode.firstCall.args[0].should.equal(authorizationCode);
model.revokeAuthorizationCode.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down Expand Up @@ -80,6 +82,7 @@ describe('AuthorizationCodeGrantType', function() {
model.saveToken.firstCall.args[0].should.eql({ accessToken: 'foo', authorizationCode: 'foobar', accessTokenExpiresAt: 'biz', refreshToken: 'bar', refreshTokenExpiresAt: 'baz', scope: 'foobiz' });
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down
2 changes: 2 additions & 0 deletions test/unit/grant-types/client-credentials-grant-type_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('ClientCredentialsGrantType', function() {
model.getUserFromClient.callCount.should.equal(1);
model.getUserFromClient.firstCall.args.should.have.length(1);
model.getUserFromClient.firstCall.args[0].should.equal(client);
model.getUserFromClient.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand All @@ -53,6 +54,7 @@ describe('ClientCredentialsGrantType', function() {
model.saveToken.firstCall.args[0].should.eql({ accessToken: 'foo', accessTokenExpiresAt: 'biz', scope: 'foobar' });
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down
2 changes: 2 additions & 0 deletions test/unit/grant-types/password-grant-type_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('PasswordGrantType', function() {
model.getUser.firstCall.args.should.have.length(2);
model.getUser.firstCall.args[0].should.equal('foo');
model.getUser.firstCall.args[1].should.equal('bar');
model.getUser.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down Expand Up @@ -57,6 +58,7 @@ describe('PasswordGrantType', function() {
model.saveToken.firstCall.args[0].should.eql({ accessToken: 'foo', accessTokenExpiresAt: 'biz', refreshToken: 'bar', refreshTokenExpiresAt: 'baz', scope: 'foobar' });
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down
7 changes: 7 additions & 0 deletions test/unit/grant-types/refresh-token-grant-type_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('RefreshTokenGrantType', function() {
model.revokeToken.callCount.should.equal(1);
model.revokeToken.firstCall.args.should.have.length(1);
model.revokeToken.firstCall.args[0].should.equal(token);
model.revokeToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand All @@ -52,6 +53,7 @@ describe('RefreshTokenGrantType', function() {
model.getRefreshToken.callCount.should.equal(1);
model.getRefreshToken.firstCall.args.should.have.length(1);
model.getRefreshToken.firstCall.args[0].should.equal('bar');
model.getRefreshToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand All @@ -72,6 +74,7 @@ describe('RefreshTokenGrantType', function() {
model.revokeToken.callCount.should.equal(1);
model.revokeToken.firstCall.args.should.have.length(1);
model.revokeToken.firstCall.args[0].should.equal(token);
model.revokeToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down Expand Up @@ -106,6 +109,7 @@ describe('RefreshTokenGrantType', function() {
model.revokeToken.callCount.should.equal(1);
model.revokeToken.firstCall.args.should.have.length(1);
model.revokeToken.firstCall.args[0].should.equal(token);
model.revokeToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down Expand Up @@ -134,6 +138,7 @@ describe('RefreshTokenGrantType', function() {
model.saveToken.firstCall.args[0].should.eql({ accessToken: 'foo', accessTokenExpiresAt: 'biz', refreshToken: 'bar', refreshTokenExpiresAt: 'baz', scope: 'foobar' });
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand All @@ -160,6 +165,7 @@ describe('RefreshTokenGrantType', function() {
model.saveToken.firstCall.args[0].should.eql({ accessToken: 'foo', accessTokenExpiresAt: 'biz', scope: 'foobar' });
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand All @@ -186,6 +192,7 @@ describe('RefreshTokenGrantType', function() {
model.saveToken.firstCall.args[0].should.eql({ accessToken: 'foo', accessTokenExpiresAt: 'biz', refreshToken: 'bar', refreshTokenExpiresAt: 'baz', scope: 'foobar' });
model.saveToken.firstCall.args[1].should.equal(client);
model.saveToken.firstCall.args[2].should.equal(user);
model.saveToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down
2 changes: 2 additions & 0 deletions test/unit/handlers/authenticate-handler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe('AuthenticateHandler', function() {
model.getAccessToken.callCount.should.equal(1);
model.getAccessToken.firstCall.args.should.have.length(1);
model.getAccessToken.firstCall.args[0].should.equal('foo');
model.getAccessToken.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down Expand Up @@ -144,6 +145,7 @@ describe('AuthenticateHandler', function() {
model.verifyScope.callCount.should.equal(1);
model.verifyScope.firstCall.args.should.have.length(2);
model.verifyScope.firstCall.args[0].should.equal('foo', 'bar');
model.verifyScope.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down
3 changes: 3 additions & 0 deletions test/unit/handlers/authorize-handler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('AuthorizeHandler', function() {
return handler.generateAuthorizationCode()
.then(function() {
model.generateAuthorizationCode.callCount.should.equal(1);
model.generateAuthorizationCode.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand All @@ -49,6 +50,7 @@ describe('AuthorizeHandler', function() {
model.getClient.callCount.should.equal(1);
model.getClient.firstCall.args.should.have.length(2);
model.getClient.firstCall.args[0].should.equal(12345);
model.getClient.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down Expand Up @@ -92,6 +94,7 @@ describe('AuthorizeHandler', function() {
model.saveAuthorizationCode.firstCall.args[0].should.eql({ authorizationCode: 'foo', expiresAt: 'bar', redirectUri: 'baz', scope: 'qux' });
model.saveAuthorizationCode.firstCall.args[1].should.equal('biz');
model.saveAuthorizationCode.firstCall.args[2].should.equal('boz');
model.saveAuthorizationCode.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/handlers/token-handler_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('TokenHandler', function() {
model.getClient.firstCall.args.should.have.length(2);
model.getClient.firstCall.args[0].should.equal(12345);
model.getClient.firstCall.args[1].should.equal('secret');
model.getClient.firstCall.thisValue.should.equal(model);
})
.catch(should.fail);
});
Expand Down