No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bizgaze.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // BizGaze as identity provider.
  2. // Validates a username/password against BizGaze's ValidateAndLogin endpoint.
  3. // Enabled only when BIZGAZE_LOGIN_URL is set (so tests/local runs stay self-contained).
  4. //
  5. // Success response shape (observed):
  6. // { status: 1, currentSession: { name, userId, tenantId, unibaseId, isAdmin, ... }, message }
  7. // Failure: status !== 1, with a `message`.
  8. function loginUrl() { return process.env.BIZGAZE_LOGIN_URL || ''; }
  9. const isEnabled = () => !!loginUrl();
  10. async function validateLogin(username, password) {
  11. const url = loginUrl();
  12. if (!url) return { ok: false, configured: false };
  13. let res;
  14. try {
  15. res = await fetch(url, {
  16. method: 'POST',
  17. headers: { 'Content-Type': 'application/json' },
  18. body: JSON.stringify({ UserName: username, Password: password, UnibaseId: '', RememberMe: false }),
  19. signal: AbortSignal.timeout(15000),
  20. });
  21. } catch (e) {
  22. return { ok: false, configured: true, error: 'BizGaze sign-in is unavailable right now' };
  23. }
  24. let data;
  25. try { data = await res.json(); } catch { return { ok: false, configured: true, error: 'Unexpected response from BizGaze' }; }
  26. const s = data && data.currentSession;
  27. if (data && data.status === 1 && s) {
  28. return {
  29. ok: true, configured: true,
  30. name: s.name || null,
  31. isAdmin: !!s.isAdmin,
  32. tenantRef: s.tenantId != null ? String(s.tenantId) : null, // BizGaze tenant (org) id
  33. bizgazeUserId: s.userId != null ? String(s.userId) : null,
  34. unibaseId: s.unibaseId || null,
  35. message: data.message || 'Login Success',
  36. };
  37. }
  38. return { ok: false, configured: true, message: (data && data.message) || 'Invalid BizGaze credentials' };
  39. }
  40. module.exports = { validateLogin, isEnabled };