You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
813 B
JavaScript
34 lines
813 B
JavaScript
const openidClient = require('openid-client');
|
|
|
|
module.exports = function oidcServiceHook(sails) {
|
|
let client = null;
|
|
|
|
return {
|
|
/**
|
|
* Runs when this Sails app loads/lifts.
|
|
*/
|
|
|
|
async initialize() {
|
|
if (sails.config.custom.oidcIssuer) {
|
|
const issuer = await openidClient.Issuer.discover(sails.config.custom.oidcIssuer);
|
|
|
|
client = new issuer.Client({
|
|
client_id: sails.config.custom.oidcClientId,
|
|
client_secret: sails.config.custom.oidcClientSecret,
|
|
redirect_uris: [sails.config.custom.oidcRedirectUri],
|
|
response_types: ['code'],
|
|
});
|
|
sails.log.info('OIDC hook has been loaded successfully');
|
|
}
|
|
},
|
|
|
|
getClient() {
|
|
return client;
|
|
},
|
|
|
|
isActive() {
|
|
return client !== null;
|
|
},
|
|
};
|
|
};
|