aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth-token.js
diff options
context:
space:
mode:
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}