Skip to content

Commit c1be546

Browse files
committed
Added and fields to mongoose OAuthTokens model, saveToken
1 parent 5f98bd1 commit c1be546

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/mongodb/model.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ var Schema = mongoose.Schema;
1313
mongoose.model('OAuthTokens', new Schema({
1414
accessToken: { type: String },
1515
accessTokenExpiresOn: { type: Date },
16+
client : { type: Object }, // `client` and `user` are required in multiple places, for example `getAccessToken()`
1617
clientId: { type: String },
1718
refreshToken: { type: String },
1819
refreshTokenExpiresOn: { type: Date },
19-
userId: { type: String }
20+
user : { type: Object },
21+
userId: { type: String },
2022
}));
2123

2224
mongoose.model('OAuthClients', new Schema({
@@ -78,10 +80,12 @@ module.exports.saveToken = function(token, client, user) {
7880
var accessToken = new OAuthTokensModel({
7981
accessToken: token.accessToken,
8082
accessTokenExpiresOn: token.accessTokenExpiresOn,
83+
client : client,
8184
clientId: client.clientId,
8285
refreshToken: token.refreshToken,
8386
refreshTokenExpiresOn: token.refreshTokenExpiresOn,
84-
userId: user._id
87+
user : user,
88+
userId: user._id,
8589
});
8690
// Can't just chain `lean()` to `save()` as we did with `findOne()` elsewhere. Instead we use `Promise` to resolve the data.
8791
return new Promise( function(resolve,reject){

0 commit comments

Comments
 (0)