sails-hook-sso
v0.0.9
Published
Single Sign-on for sails.js using passport and passport-sso
Downloads
6
Maintainers
Readme
sails-hook-sso
Passport-SSO for the Sails framework. This is still in development and not ready for production use.
This project relies on passport-sso
npm install passport-sso --save
Getting started
1.) Create a sso.js file in the sails project's config directory (i.e: config/sso.js)
2.) Add the following to your new sso.js config file. Make sure to change the values of each setting to match that of your database connections and schema
/***************************************************************************
* *
* Override sails-hook-sso database connections *
* *
***************************************************************************/
connections: {
hosts : "{hosts-connection}", # Connection for host table/collection (config/connections.js)
providers : "{providers-connection}", # Connection for providers table/collection (config/connections.js)
users : "{users-connection}", # Connection for users table/collection (config/connections.js)
passports : "{passports-connection}", # Connection for passports table/collection (config/connections.js)
groups : "{groupsConnection}", # Connection for groups table/collection (config/connections.js)
},
/***************************************************************************
* *
* Override sails-hook-sso database table/collection names *
* *
***************************************************************************/
collections: {
hosts : "sso_hosts", # Name of your host table/collection
providers : "sso_providers", # Name of your provider table/collection
users : "sso_users", # Name of your user table/collection
passports : "sso_passports", # Name of your passport table/collection
groups : "sso_groups", # Name of your group table/collection
}
1.) Add a host controller (i.e: api/controllers/V1/Settings/Global/HostsController.js) to your sails project:
module.exports = {
/**
* `HostsController.index()`
* @author :: Matt McCarty
* @description :: Returns all supported hosts from the global configuration
* @method :: GET
* @example :: version#/settings/global/hosts
*/
index: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.hosts.index(req, res);
},
/**
* `HostsController.create()`
* @author :: Matt McCarty
* @description :: Add a new host to the global configuration
* @method :: POST
* @example :: version#/settings/global/hosts/create
*/
create: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.hosts.create(req, res);
},
/**
* `HostsController.update()`
* @author :: Matt McCarty
* @description :: Update an existing host in the database
* @method :: PUT
* @example :: version#/settings/global/hosts/update
*/
update: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.hosts.update(req, res);
},
/**
* `HostsController.destroy()`
* @author :: Matt McCarty
* @description :: Deletes an existing host record from the database
* @method :: DELETE
* @example :: version#/settings/global/hosts/destroy
*/
destroy: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.hosts.destroy(req, res);
}
};
2.) Add a groups controller (i.e: api/controllers/V1/Settings/Global/GroupsController.js) to your sails project:
module.exports = {
/**
* `GroupsController.index()`
* @author :: Matt McCarty
* @description :: Returns all supported groups from the global configuration
* @method :: GET
* @example :: version#/settings/global/groups
*/
index: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.groups.index(req, res);
},
/**
* `GroupsController.create()`
* @author :: Matt McCarty
* @description :: Add a new group to the global configuration
* @method :: POST
* @example :: version#/settings/global/hogroupssts/create
*/
create: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.groups.create(req, res);
},
/**
* `GroupsController.update()`
* @author :: Matt McCarty
* @description :: Update an existing group in the database
* @method :: PUT
* @example :: version#/settings/global/groups/update
*/
update: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.groups.update(req, res);
},
/**
* `GroupsController.destroy()`
* @author :: Matt McCarty
* @description :: Deletes an existing group record from the database
* @method :: DELETE
* @example :: version#/settings/global/groups/destroy
*/
destroy: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.groups.destroy(req, res);
}
};
3.) Add a providers controller (i.e: api/controllers/V1/Settings/Global/ProvidersController.js) to your sails project:
module.exports = {
/**
* `ProvidersController.index()`
* @author :: Matt McCarty
* @description :: Returns all supported providers from the global configuration
* @method :: GET
* @example :: version#/settings/global/providers
*/
index: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.providers.index(req, res);
},
/**
* `ProvidersController.defaults()`
* @author :: Matt McCarty
* @description :: Returns a list of the provider default settings
* @method :: GET
* @example :: version#/settings/global/defaults
*/
defaults: function (req, res) {
return sails.controllers.sso.providers.defaults(req, res);
},
/**
* `ProvidersController.create()`
* @author :: Matt McCarty
* @description :: Add a new provider to the global configuration
* @method :: POST
* @example :: version#/settings/global/providers/create
*/
create: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.providers.create(req, res);
},
/**
* `ProvidersController.update()`
* @author :: Matt McCarty
* @description :: Update an existing provider in the database
* @method :: PUT
* @example :: version#/settings/global/providers/update
*/
update: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.providers.update(req, res);
},
/**
* `ProvidersController.destroy()`
* @author :: Matt McCarty
* @description :: Deletes an existing provider record from the database
* @method :: DELETE
* @example :: version#/settings/global/providers/destroy
*/
destroy: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.providers.destroy(req, res);
}
};
4.) Add a passports controller (i.e: api/controllers/V1/User/Auth/PassportsController.js) to your sails project:
module.exports = {
/**
* `PassportsController.index()`
* @author :: Matt McCarty
* @description :: Returns all supported pasports from the global configuration
* @method :: GET
* @example :: version#/user/auth/pasports
*/
index: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.pasports.index(req, res);
},
/**
* `PassportsController.create()`
* @author :: Matt McCarty
* @description :: Add a new passport to the global configuration
* @method :: POST
* @example :: version#/user/auth/create
*/
create: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.pasports.create(req, res);
},
/**
* `PassportsController.update()`
* @author :: Matt McCarty
* @description :: Update an existing passport in the database
* @method :: PUT
* @example :: version#/user/auth/update
*/
update: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.pasports.update(req, res);
},
/**
* `PassportsController.destroy()`
* @author :: Matt McCarty
* @description :: Deletes an existing passport record from the database
* @method :: DELETE
* @example :: version#/user/auth/destroy
*/
destroy: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.pasports.destroy(req, res);
}
};
5.) Add a user controller (i.e: api/controllers/V1/UsersController.js) to your sails project:
module.exports = {
/**
* `UsersController.index()`
* @author :: Matt McCarty
* @description :: Returns user profile page
* @method :: GET
* @example :: version#/user
*/
index: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.users.index(req, res);
},
/**
* `UsersController.register()`
* @author :: Matt McCarty
* @description :: Creates (registers) a new user
* @method :: POST
* @example :: version#/user/register
*/
register: function (req, res) {
// Defined in sails-hook-sso module
return sails.controllers.sso.users.register(req, res);
}
};
6.) Configure your routes in config/routes.js to match the new controllers and actions
7.) Run sails:
sails lift
8.) Make a REST API request to one of the endpoints. For example:
POST = /v1/settings/global/hosts/create
Values = {
host : 'localhost:1337',
master : 1,
children: []
}
to be continued...