sso.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Cause an error on startup if the Drupal server is unreachable.
  2. Meteor.startup(function () {
  3. sso = new DrupalSSO();
  4. if (!sso.state.online) {
  5. throw new Meteor.Error('startup', "Could not reach the Drupal server.");
  6. }
  7. });
  8. Meteor.methods({
  9. /**
  10. * Parse Meteor settings to initialize the SSO state from the server.
  11. */
  12. "drupal-sso.initState": function () {
  13. var settings = Meteor.settings['drupal-sso'];
  14. var site = settings.site;
  15. var appToken = settings.appToken;
  16. if (!settings) {
  17. throw new Meteor.Error('invalid-settings', "Invalid settings: 'drupal-sso' key not found.");
  18. }
  19. if (!site) {
  20. throw new Meteor.Error('invalid-settings', "Invalid settings: 'drupal-sso.site' key not found.");
  21. }
  22. if (!appToken) {
  23. throw new Meteor.Error('invalid-settings', "Invalid settings: 'drupal-sso.appToken' key not found.");
  24. }
  25. var options = {
  26. params: {
  27. appToken: settings.appToken
  28. }
  29. };
  30. try {
  31. var ret = HTTP.get(site + "/meteor/siteInfo", options);
  32. info = JSON.parse(ret.content);
  33. info.online = true;
  34. }
  35. catch (err) {
  36. info = {
  37. cookieName: undefined,
  38. anonymousName: undefined,
  39. online: false
  40. };
  41. Meteor._debug("Error: ", err);
  42. }
  43. Meteor._debug("initState returning", info);
  44. return info;
  45. },
  46. "drupal-sso.whoami": function () {
  47. },
  48. });