aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/oauth-client.js
blob: 45834c5a5374328d238f20a78f68a534d36e9cfa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const mongoose = require('mongoose')

// ---------------------------------------------------------------------------

const OAuthClientSchema = mongoose.Schema({
  clientSecret: String,
  grants: Array,
  redirectUris: Array
})

OAuthClientSchema.path('clientSecret').required(true)

OAuthClientSchema.statics = {
  getByIdAndSecret: getByIdAndSecret,
  list: list,
  loadFirstClient: loadFirstClient
}

mongoose.model('OAuthClient', OAuthClientSchema)

// ---------------------------------------------------------------------------

function list (callback) {
  return this.find(callback)
}

function loadFirstClient (callback) {
  return this.findOne({}, callback)
}

function getByIdAndSecret (id, clientSecret) {
  return this.findOne({ _id: id, clientSecret: clientSecret }).exec()
}