Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. {
  2. "ldap": {
  3. "provider": "ldap",
  4. "authScheme":"ldap",
  5. "module": "passport-ldapauth",
  6. "authPath": "/auth/ldap",
  7. "successRedirect": "/auth/account",
  8. "failureRedirect": "/msad",
  9. "json":true,
  10. "failureFlash": false,
  11. "session": false,
  12. "setToken":true,
  13. "LdapAttributeForLogin": "mail",
  14. "LdapAttributeForUsername": "sAMAccountName",
  15. "LdapAttributeForMail": "mail",
  16. "server":{
  17. "url": "ldaps://servername.domain:636",
  18. "bindDn": "CN=Username,CN=Users,DC=ad,DC=Customer,DC=org",
  19. "bindCredentials": "password for bind user",
  20. "searchBase": "dc=ad,dc=Customer,dc=org",
  21. "searchAttributes": ["cn", "mail", "givenname"],
  22. "searchFilter": "(&(mail={{username}}))"
  23. }
  24. }
  25. }
  26.  
  27. 'use strict';
  28.  
  29. var loopback = require('loopback');
  30. var boot = require('loopback-boot');
  31.  
  32. //required for https config
  33. var https = require('https');
  34. var fs = require('fs');
  35.  
  36. var app = module.exports = loopback();
  37.  
  38. //custom addition to see if it works
  39.  
  40. var graphqlHTTP = require('express-graphql');
  41. var graphqlvar = require('graphql');
  42.  
  43. var schema =require('./middleware/schema');
  44.  
  45. // configure view handler
  46. var path = require('path');
  47. app.set('view engine', 'ejs');
  48. app.set('views', path.join(__dirname, 'views'));
  49. app.use(loopback.token());
  50.  
  51. // Passport configurators..
  52. var loopbackPassport = require('loopback-component-passport');
  53. var PassportConfigurator = loopbackPassport.PassportConfigurator;
  54. var passportConfigurator = new PassportConfigurator(app);
  55.  
  56. var config = {};
  57. try {
  58. config = require('./providers.json');
  59. } catch(err) {
  60. console.error('Please configure your passport strategy in `providers.json`.');
  61. console.error('Copy `providers.json.template` to `providers.json` and replace the clientID/clientSecret values with your own.');
  62. process.exit(1);
  63. }
  64. // Initialize passport
  65. passportConfigurator.init(true);
  66. app.use('/graphql', graphqlHTTP({
  67. schema: schema,
  68. graphiql: true
  69. }));
  70.  
  71. //https config
  72.  
  73. var options = {
  74. pfx: fs.readFileSync('path to pfx file'),
  75. passphrase: 'passphrase'
  76. };
  77. var options_ldap = {
  78. ca: fs.readFileSync('path to cert file')
  79. };
  80.  
  81.  
  82.  
  83.  
  84. app.start = function() {
  85. // create ssl server
  86. var server = null;
  87. server = https.createServer(options, app);
  88. // start the web server
  89.  
  90. /*return app.listen(function() {
  91. app.emit('started');
  92. var baseUrl = app.get('url').replace(//$/, '');
  93. console.log('Web server listening at: %s', baseUrl);
  94. if (app.get('loopback-component-explorer')) {
  95. var explorerPath = app.get('loopback-component-explorer').mountPath;
  96. console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
  97. }
  98. });*/
  99. server.listen(app.get('port'), function() {
  100. var baseUrl = 'https://' + app.get('host') + ':' + app.get('port');
  101. //var baseUrl = 'https://' + app.get('host');
  102. //app.emit('started', baseUrl);
  103. app.emit('started');
  104. console.log('Web server listening at: %s', baseUrl);
  105. console.log('LoopBack server listening @ %s%s', baseUrl, '/');
  106. if (app.get('loopback-component-explorer')) {
  107. var explorerPath = app.get('loopback-component-explorer').mountPath;
  108. console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
  109. }
  110. });
  111. return server;
  112. };
  113.  
  114. // Bootstrap the application, configure models, datasources and middleware.
  115. // Sub-apps like REST API are mounted via boot scripts.
  116. boot(app, __dirname, function(err) {
  117. if (err) throw err;
  118.  
  119. // start the server if `$ node server.js`
  120. if (require.main === module)
  121. app.start();
  122. });
  123.  
  124. // Set up related models
  125. passportConfigurator.setupModels({
  126. userModel: app.models.AppUser,
  127. userIdentityModel: app.models.userIdentity,
  128. userCredentialModel: app.models.userCredential
  129. });
  130. // Configure passport strategies for third party auth providers
  131. for(var s in config) {
  132. var c = config[s];
  133. c.session = c.session !== false;
  134. /*c.createAccessToken=function(user,cb){
  135. user.accessTokens.create({
  136. created: new Date(),
  137. ttl: ttl
  138. },cb);
  139. }*/
  140. //adjust ldap config to add tls options
  141. if (c.authScheme=="ldap"){
  142. if (c.server!=null){
  143.  
  144. //harcode now and make generic later
  145. c.server.tlsOptions=options_ldap;
  146. }
  147. }
  148. passportConfigurator.configureProvider(s, c);
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement