Ingen beskrivning
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

auth.js 5.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.AuthBlockingService = void 0;
  4. const backend = require("../backend");
  5. const identityPlatform = require("../../../gcp/identityPlatform");
  6. const events = require("../../../functions/events");
  7. const error_1 = require("../../../error");
  8. const utils_1 = require("../../../utils");
  9. const index_1 = require("./index");
  10. class AuthBlockingService {
  11. constructor() {
  12. this.name = "authblocking";
  13. this.api = "identitytoolkit.googleapis.com";
  14. this.triggerQueue = Promise.resolve();
  15. this.ensureTriggerRegion = index_1.noop;
  16. }
  17. validateTrigger(endpoint, wantBackend) {
  18. if (!backend.isBlockingTriggered(endpoint)) {
  19. return;
  20. }
  21. const blockingEndpoints = backend
  22. .allEndpoints(wantBackend)
  23. .filter((ep) => backend.isBlockingTriggered(ep));
  24. if (blockingEndpoints.find((ep) => ep.blockingTrigger.eventType === endpoint.blockingTrigger.eventType &&
  25. ep.id !== endpoint.id)) {
  26. throw new error_1.FirebaseError(`Can only create at most one Auth Blocking Trigger for ${endpoint.blockingTrigger.eventType} events`);
  27. }
  28. }
  29. configChanged(newConfig, config) {
  30. var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
  31. if (((_b = (_a = newConfig.triggers) === null || _a === void 0 ? void 0 : _a.beforeCreate) === null || _b === void 0 ? void 0 : _b.functionUri) !==
  32. ((_d = (_c = config.triggers) === null || _c === void 0 ? void 0 : _c.beforeCreate) === null || _d === void 0 ? void 0 : _d.functionUri) ||
  33. ((_f = (_e = newConfig.triggers) === null || _e === void 0 ? void 0 : _e.beforeSignIn) === null || _f === void 0 ? void 0 : _f.functionUri) !== ((_h = (_g = config.triggers) === null || _g === void 0 ? void 0 : _g.beforeSignIn) === null || _h === void 0 ? void 0 : _h.functionUri)) {
  34. return true;
  35. }
  36. if (!!((_j = newConfig.forwardInboundCredentials) === null || _j === void 0 ? void 0 : _j.accessToken) !==
  37. !!((_k = config.forwardInboundCredentials) === null || _k === void 0 ? void 0 : _k.accessToken) ||
  38. !!((_l = newConfig.forwardInboundCredentials) === null || _l === void 0 ? void 0 : _l.idToken) !==
  39. !!((_m = config.forwardInboundCredentials) === null || _m === void 0 ? void 0 : _m.idToken) ||
  40. !!((_o = newConfig.forwardInboundCredentials) === null || _o === void 0 ? void 0 : _o.refreshToken) !==
  41. !!((_p = config.forwardInboundCredentials) === null || _p === void 0 ? void 0 : _p.refreshToken)) {
  42. return true;
  43. }
  44. return false;
  45. }
  46. async registerTriggerLocked(endpoint) {
  47. const newBlockingConfig = await identityPlatform.getBlockingFunctionsConfig(endpoint.project);
  48. const oldBlockingConfig = (0, utils_1.cloneDeep)(newBlockingConfig);
  49. if (endpoint.blockingTrigger.eventType === events.v1.BEFORE_CREATE_EVENT) {
  50. newBlockingConfig.triggers = Object.assign(Object.assign({}, newBlockingConfig.triggers), { beforeCreate: {
  51. functionUri: endpoint.uri,
  52. } });
  53. }
  54. else {
  55. newBlockingConfig.triggers = Object.assign(Object.assign({}, newBlockingConfig.triggers), { beforeSignIn: {
  56. functionUri: endpoint.uri,
  57. } });
  58. }
  59. newBlockingConfig.forwardInboundCredentials = Object.assign(Object.assign({}, oldBlockingConfig.forwardInboundCredentials), endpoint.blockingTrigger.options);
  60. if (!this.configChanged(newBlockingConfig, oldBlockingConfig)) {
  61. return;
  62. }
  63. await identityPlatform.setBlockingFunctionsConfig(endpoint.project, newBlockingConfig);
  64. }
  65. registerTrigger(ep) {
  66. if (!backend.isBlockingTriggered(ep)) {
  67. return Promise.resolve();
  68. }
  69. this.triggerQueue = this.triggerQueue.then(() => this.registerTriggerLocked(ep));
  70. return this.triggerQueue;
  71. }
  72. async unregisterTriggerLocked(endpoint) {
  73. var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
  74. const blockingConfig = await identityPlatform.getBlockingFunctionsConfig(endpoint.project);
  75. if (endpoint.uri !== ((_b = (_a = blockingConfig.triggers) === null || _a === void 0 ? void 0 : _a.beforeCreate) === null || _b === void 0 ? void 0 : _b.functionUri) &&
  76. endpoint.uri !== ((_d = (_c = blockingConfig.triggers) === null || _c === void 0 ? void 0 : _c.beforeSignIn) === null || _d === void 0 ? void 0 : _d.functionUri)) {
  77. return;
  78. }
  79. if (endpoint.uri === ((_f = (_e = blockingConfig.triggers) === null || _e === void 0 ? void 0 : _e.beforeCreate) === null || _f === void 0 ? void 0 : _f.functionUri)) {
  80. (_g = blockingConfig.triggers) === null || _g === void 0 ? true : delete _g.beforeCreate;
  81. }
  82. if (endpoint.uri === ((_j = (_h = blockingConfig.triggers) === null || _h === void 0 ? void 0 : _h.beforeSignIn) === null || _j === void 0 ? void 0 : _j.functionUri)) {
  83. (_k = blockingConfig.triggers) === null || _k === void 0 ? true : delete _k.beforeSignIn;
  84. }
  85. await identityPlatform.setBlockingFunctionsConfig(endpoint.project, blockingConfig);
  86. }
  87. unregisterTrigger(ep) {
  88. if (!backend.isBlockingTriggered(ep)) {
  89. return Promise.resolve();
  90. }
  91. this.triggerQueue = this.triggerQueue.then(() => this.unregisterTriggerLocked(ep));
  92. return this.triggerQueue;
  93. }
  94. }
  95. exports.AuthBlockingService = AuthBlockingService;