Skip to content

Instantly share code, notes, and snippets.

@dheniges
Forked from jcontonio/strategy.js
Last active August 29, 2015 14:09
Show Gist options
  • Save dheniges/1de7ad6a216cbc691c3d to your computer and use it in GitHub Desktop.
Save dheniges/1de7ad6a216cbc691c3d to your computer and use it in GitHub Desktop.
// Web server does this, hits an endpoint
// { type: 'saml', strategy: company.strategy }
var company = Company.findByDomain(__domain);
if (company) {
var strategy = company.strategy;
}
var companyStrat = function() {
// it's a SAML type
if (strategy.type === 'saml') {
// that strategy object looks like this, specific to the company, stored in the company.
return (
{
path: '/login/callback',
entryPoint: '', //path to msdev-sts..../adfs/ls
issuer: __domain + '/login/callback',
callbackUrl: __domain + '/login/callback',
// We don't know what this CERT is, is it our SSL cert?
cert: 'MIICizCCAfQCCQCY8tKaMc0BMjANBgkqh ... W==',
identifierFormat: null
});
}
}
// Client Server
router.post(_domain + '/login/callback', function(req, res) {
if (req.sender === companyStrat.entryPoint) {
API.post('/login/user', function(data){
data.secretAccessToken = process.env.SECRET_ACCESS_TOKEN;
data.user = req.user;
}).done(err, res) {
var lmsAPIToken = res.token;
res.send(index.ejs, {token: lmsAPIToken});
}
}
});
// Web server - Setting it
passport.use(new companyStrat);
if (!fs.open('/adfs/FederationMetadata.xml','r')) {
var metaData = passport.generateServiceProviderMetadata(strategy.cert);
fs.write(__dir + '/adfs/FederationMetadata.xml', metaData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment