@positivegrid/pg-mongoose-schema 26.7.0 → 27.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/models/oauth.js +14 -4
- package/models/user.js +2 -1
- package/package.json +1 -1
package/models/oauth.js
CHANGED
|
@@ -16,7 +16,12 @@ module.exports = function (mongoose) {
|
|
|
16
16
|
code: { type: String, required: true },
|
|
17
17
|
clientId: { type: ObjectId, ref: 'OathClient', required: true },
|
|
18
18
|
redirectURI: { type: String, required: true },
|
|
19
|
-
userId: { type:
|
|
19
|
+
userId: { type: ObjectId, ref: 'User', required: true },
|
|
20
|
+
scopes: [{ type: String, required: true }],
|
|
21
|
+
expiresAt: { type: Date, required: true },
|
|
22
|
+
codeChallenge: { type: String },
|
|
23
|
+
codeChallengeMethod: { type: String, default: 'S256' },
|
|
24
|
+
date: { type: Date, default: Date.now }
|
|
20
25
|
}, { collection: 'auth_authorizationCodes', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
21
26
|
AuthorizationCodeSchema.plugin(deepPopulate, {})
|
|
22
27
|
|
|
@@ -24,15 +29,20 @@ module.exports = function (mongoose) {
|
|
|
24
29
|
const AccessTokenSchema = new Schema({
|
|
25
30
|
token: { type: String, required: true },
|
|
26
31
|
expirationDate: { type: Date, required: true },
|
|
27
|
-
userId: { type:
|
|
28
|
-
clientId: { type: ObjectId, ref: 'OathClient', required: true }
|
|
32
|
+
userId: { type: ObjectId, ref: 'User', required: true },
|
|
33
|
+
clientId: { type: ObjectId, ref: 'OathClient', required: true },
|
|
34
|
+
scopes: [{ type: String, required: true }],
|
|
35
|
+
date: { type: Date, default: Date.now }
|
|
29
36
|
}, { collection: 'auth_accessTokens', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
30
37
|
|
|
31
38
|
// refreshTokens
|
|
32
39
|
const RefreshTokenSchema = new Schema({
|
|
33
40
|
refreshToken: { type: String, required: true },
|
|
34
41
|
clientId: { type: ObjectId, ref: 'OathClient', required: true },
|
|
35
|
-
|
|
42
|
+
expirationDate: { type: Date, required: true },
|
|
43
|
+
userId: { type: ObjectId, ref: 'User', required: true },
|
|
44
|
+
scopes: [{ type: String, required: true }],
|
|
45
|
+
date: { type: Date, default: Date.now }
|
|
36
46
|
}, { collection: 'auth_refreshTokens', toJSON: { virtuals: true }, toObject: { virtuals: true } })
|
|
37
47
|
|
|
38
48
|
mongoose.model('OauthClient', clientSchema)
|
package/models/user.js
CHANGED
|
@@ -96,6 +96,7 @@ module.exports = function (mongoose) {
|
|
|
96
96
|
fb_access_token: { type: String, default: null },
|
|
97
97
|
facebook_id: { type: String, default: null },
|
|
98
98
|
shopify_id: { type: Schema.Types.Mixed, default: null },
|
|
99
|
+
bk_username: [{ type: String }],
|
|
99
100
|
auth: {
|
|
100
101
|
firebase_id: { type: String },
|
|
101
102
|
google_id: { type: String },
|
|
@@ -275,7 +276,7 @@ module.exports = function (mongoose) {
|
|
|
275
276
|
}
|
|
276
277
|
if (!bgUser) {
|
|
277
278
|
throw new ApiErrorCode('USER_NOT_EXIST', `Cannot find user ${username}`)
|
|
278
|
-
} else if (!
|
|
279
|
+
} else if (!bgUser.authenticate(password)) {
|
|
279
280
|
throw new ApiErrorCode('USER_UNAUTHORIZED', 'unauthorized')
|
|
280
281
|
}
|
|
281
282
|
return bgUser
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@positivegrid/pg-mongoose-schema",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "27.0.0",
|
|
4
4
|
"description": "Positive Grid mongoose schema",
|
|
5
5
|
"author": "Ferrari Lee <shiyung@positivegrid.com>",
|
|
6
6
|
"homepage": "https://git.positivegrid.com:8443/backend/pg-mongoose-schema",
|