aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/models/oauth-client.js
blob: a1aefa985283ad279a6e925e3a918784b4c8e244 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13











                                                                              

                   












                                                                              
                                              
                                                                     
 
const mongoose = require('mongoose')

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

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

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

OAuthClientSchema.statics = {
  getByIdAndSecret,
  list,
  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()
}