sails-hook-sso
Passport-SSO for the Sails framework. This is still in development and not ready for production use.
passport-sso
This project relies onnpm 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/ providers : "{providers-connection}" # Connection for providers table/ users : "{users-connection}" # Connection for users table/ passports : "{passports-connection}" # Connection for passports table/ groups : "{groupsConnection}" # Connection for groups table/ /*************************************************************************** * * * 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:
moduleexports = /** * `HostsController.index()` * @author :: Matt McCarty * @description :: Returns all supported hosts from the global configuration * @method :: GET * @example :: version#/settings/global/hosts */ { // Defined in sails-hook-sso module return sailscontrollersssohostsindexreq res; } /** * `HostsController.create()` * @author :: Matt McCarty * @description :: Add a new host to the global configuration * @method :: POST * @example :: version#/settings/global/hosts/create */ { // Defined in sails-hook-sso module return sailscontrollersssohosts; } /** * `HostsController.update()` * @author :: Matt McCarty * @description :: Update an existing host in the database * @method :: PUT * @example :: version#/settings/global/hosts/update */ { // Defined in sails-hook-sso module return sailscontrollersssohosts; } /** * `HostsController.destroy()` * @author :: Matt McCarty * @description :: Deletes an existing host record from the database * @method :: DELETE * @example :: version#/settings/global/hosts/destroy */ { // Defined in sails-hook-sso module return sailscontrollersssohosts; };
2.) Add a groups controller (i.e: api/controllers/V1/Settings/Global/GroupsController.js) to your sails project:
moduleexports = /** * `GroupsController.index()` * @author :: Matt McCarty * @description :: Returns all supported groups from the global configuration * @method :: GET * @example :: version#/settings/global/groups */ { // Defined in sails-hook-sso module return sailscontrollersssogroupsindexreq res; } /** * `GroupsController.create()` * @author :: Matt McCarty * @description :: Add a new group to the global configuration * @method :: POST * @example :: version#/settings/global/hogroupssts/create */ { // Defined in sails-hook-sso module return sailscontrollersssogroups; } /** * `GroupsController.update()` * @author :: Matt McCarty * @description :: Update an existing group in the database * @method :: PUT * @example :: version#/settings/global/groups/update */ { // Defined in sails-hook-sso module return sailscontrollersssogroups; } /** * `GroupsController.destroy()` * @author :: Matt McCarty * @description :: Deletes an existing group record from the database * @method :: DELETE * @example :: version#/settings/global/groups/destroy */ { // Defined in sails-hook-sso module return sailscontrollersssogroups; };
3.) Add a providers controller (i.e: api/controllers/V1/Settings/Global/ProvidersController.js) to your sails project:
moduleexports = /** * `ProvidersController.index()` * @author :: Matt McCarty * @description :: Returns all supported providers from the global configuration * @method :: GET * @example :: version#/settings/global/providers */ { // Defined in sails-hook-sso module return sailscontrollersssoprovidersindexreq res; } /** * `ProvidersController.defaults()` * @author :: Matt McCarty * @description :: Returns a list of the provider default settings * @method :: GET * @example :: version#/settings/global/defaults */ { return sailscontrollersssoproviders; } /** * `ProvidersController.create()` * @author :: Matt McCarty * @description :: Add a new provider to the global configuration * @method :: POST * @example :: version#/settings/global/providers/create */ { // Defined in sails-hook-sso module return sailscontrollersssoproviders; } /** * `ProvidersController.update()` * @author :: Matt McCarty * @description :: Update an existing provider in the database * @method :: PUT * @example :: version#/settings/global/providers/update */ { // Defined in sails-hook-sso module return sailscontrollersssoproviders; } /** * `ProvidersController.destroy()` * @author :: Matt McCarty * @description :: Deletes an existing provider record from the database * @method :: DELETE * @example :: version#/settings/global/providers/destroy */ { // Defined in sails-hook-sso module return sailscontrollersssoproviders; };
4.) Add a passports controller (i.e: api/controllers/V1/User/Auth/PassportsController.js) to your sails project:
moduleexports = /** * `PassportsController.index()` * @author :: Matt McCarty * @description :: Returns all supported pasports from the global configuration * @method :: GET * @example :: version#/user/auth/pasports */ { // Defined in sails-hook-sso module return sailscontrollersssopasportsindexreq res; } /** * `PassportsController.create()` * @author :: Matt McCarty * @description :: Add a new passport to the global configuration * @method :: POST * @example :: version#/user/auth/create */ { // Defined in sails-hook-sso module return sailscontrollersssopasports; } /** * `PassportsController.update()` * @author :: Matt McCarty * @description :: Update an existing passport in the database * @method :: PUT * @example :: version#/user/auth/update */ { // Defined in sails-hook-sso module return sailscontrollersssopasports; } /** * `PassportsController.destroy()` * @author :: Matt McCarty * @description :: Deletes an existing passport record from the database * @method :: DELETE * @example :: version#/user/auth/destroy */ { // Defined in sails-hook-sso module return sailscontrollersssopasports; };
5.) Add a user controller (i.e: api/controllers/V1/UsersController.js) to your sails project:
moduleexports = /** * `UsersController.index()` * @author :: Matt McCarty * @description :: Returns user profile page * @method :: GET * @example :: version#/user */ { // Defined in sails-hook-sso module return sailscontrollersssousersindexreq res; } /** * `UsersController.register()` * @author :: Matt McCarty * @description :: Creates (registers) a new user * @method :: POST * @example :: version#/user/register */ { // Defined in sails-hook-sso module return sailscontrollersssousers; };
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/createValues = host : 'localhost:1337' master : 1 children:
to be continued...