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

            



                                                     

                               

                     

                               








                                               









                                                 
                     







                         

 


                                                                              
                                            


                                     
                                            

 








                                                    
 
'use strict'

module.exports = function (sequelize, DataTypes) {
  const OAuthClient = sequelize.define('OAuthClient',
    {
      clientId: {
        type: DataTypes.STRING,
        allowNull: false
      },
      clientSecret: {
        type: DataTypes.STRING,
        allowNull: false
      },
      grants: {
        type: DataTypes.ARRAY(DataTypes.STRING)
      },
      redirectUris: {
        type: DataTypes.ARRAY(DataTypes.STRING)
      }
    },
    {
      indexes: [
        {
          fields: [ 'clientId' ],
          unique: true
        },
        {
          fields: [ 'clientId', 'clientSecret' ],
          unique: true
        }
      ],
      classMethods: {
        getByIdAndSecret,
        list,
        loadFirstClient
      }
    }
  )

  return OAuthClient
}

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

function list (callback) {
  return this.findAll().asCallback(callback)
}

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

function getByIdAndSecret (clientId, clientSecret) {
  const query = {
    where: {
      clientId: clientId,
      clientSecret: clientSecret
    }
  }

  return this.findOne(query)
}