diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-07-01 16:03:53 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-07-01 16:03:53 +0200 |
commit | 69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd (patch) | |
tree | 8659f819818a3da6419959b6b7838a7f0557c948 /server/models/oauth-token.js | |
parent | a3ee6fa22dee4b68fcde9cd23708b471db446e11 (diff) | |
download | PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.tar.gz PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.tar.zst PeerTube-69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd.zip |
OAuth/User models refractoring -> use mongoose api
Diffstat (limited to 'server/models/oauth-token.js')
-rw-r--r-- | server/models/oauth-token.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/server/models/oauth-token.js b/server/models/oauth-token.js new file mode 100644 index 000000000..5da5da417 --- /dev/null +++ b/server/models/oauth-token.js | |||
@@ -0,0 +1,34 @@ | |||
1 | const mongoose = require('mongoose') | ||
2 | |||
3 | // --------------------------------------------------------------------------- | ||
4 | |||
5 | const OAuthTokenSchema = mongoose.Schema({ | ||
6 | accessToken: String, | ||
7 | accessTokenExpiresOn: Date, | ||
8 | client: { type: mongoose.Schema.Types.ObjectId, ref: 'OAuthClient' }, | ||
9 | refreshToken: String, | ||
10 | refreshTokenExpiresOn: Date, | ||
11 | user: { type: mongoose.Schema.Types.ObjectId, ref: 'User' } | ||
12 | }) | ||
13 | |||
14 | OAuthTokenSchema.path('accessToken').required(true) | ||
15 | OAuthTokenSchema.path('client').required(true) | ||
16 | OAuthTokenSchema.path('user').required(true) | ||
17 | |||
18 | OAuthTokenSchema.statics = { | ||
19 | loadByRefreshToken: loadByRefreshToken, | ||
20 | loadByTokenAndPopulateUser: loadByTokenAndPopulateUser | ||
21 | } | ||
22 | |||
23 | mongoose.model('OAuthToken', OAuthTokenSchema) | ||
24 | |||
25 | // --------------------------------------------------------------------------- | ||
26 | |||
27 | function loadByRefreshToken (refreshToken, callback) { | ||
28 | return this.findOne({ refreshToken: refreshToken }, callback) | ||
29 | } | ||
30 | |||
31 | function loadByTokenAndPopulateUser (bearerToken, callback) { | ||
32 | // FIXME: allow to use callback | ||
33 | return this.findOne({ accessToken: bearerToken }).populate('user') | ||
34 | } | ||