aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth-token.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-07-01 16:03:53 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-07-01 16:03:53 +0200
commit69b0a27cbbd69ca019eb7db5f917b1dd06dc82cd (patch)
tree8659f819818a3da6419959b6b7838a7f0557c948 /server/models/oauth-token.js
parenta3ee6fa22dee4b68fcde9cd23708b471db446e11 (diff)
downloadPeerTube-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.js34
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 @@
1const mongoose = require('mongoose')
2
3// ---------------------------------------------------------------------------
4
5const 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
14OAuthTokenSchema.path('accessToken').required(true)
15OAuthTokenSchema.path('client').required(true)
16OAuthTokenSchema.path('user').required(true)
17
18OAuthTokenSchema.statics = {
19 loadByRefreshToken: loadByRefreshToken,
20 loadByTokenAndPopulateUser: loadByTokenAndPopulateUser
21}
22
23mongoose.model('OAuthToken', OAuthTokenSchema)
24
25// ---------------------------------------------------------------------------
26
27function loadByRefreshToken (refreshToken, callback) {
28 return this.findOne({ refreshToken: refreshToken }, callback)
29}
30
31function loadByTokenAndPopulateUser (bearerToken, callback) {
32 // FIXME: allow to use callback
33 return this.findOne({ accessToken: bearerToken }).populate('user')
34}