@camstack/addon-auth 1.2.137 → 1.2.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_dist = require("../dist-C3Gd6eZD.js");
5
+ const require_dist = require("../dist-CiG_dP05.js");
6
6
  let node_crypto = require("node:crypto");
7
7
  node_crypto = require_dist.__toESM(node_crypto);
8
8
  //#region ../../node_modules/jose/dist/webapi/lib/buffer_utils.js
@@ -704,6 +704,186 @@ function createRemoteJWKSet(url, options) {
704
704
  });
705
705
  }
706
706
  //#endregion
707
+ //#region src/oidc/oidc-connection-schema.ts
708
+ var DEFAULT_OIDC_ICON = "shield-check";
709
+ var OIDC_CONNECTION_FORM_SCHEMA = { sections: [{
710
+ id: "identity",
711
+ title: "Identity",
712
+ fields: [{
713
+ type: "text",
714
+ key: "displayName",
715
+ label: "Display name",
716
+ description: "Shown on the login button.",
717
+ default: "OpenID Connect"
718
+ }, {
719
+ type: "icon",
720
+ key: "icon",
721
+ label: "Icon",
722
+ description: "Shown on the login button.",
723
+ default: DEFAULT_OIDC_ICON
724
+ }]
725
+ }, {
726
+ id: "idp",
727
+ title: "Identity provider",
728
+ fields: [
729
+ {
730
+ type: "text",
731
+ key: "issuerUrl",
732
+ label: "Issuer URL",
733
+ description: "IdP base URL — discovery doc lives at <issuer>/.well-known/openid-configuration.",
734
+ default: ""
735
+ },
736
+ {
737
+ type: "text",
738
+ key: "clientId",
739
+ label: "Client ID",
740
+ default: ""
741
+ },
742
+ {
743
+ type: "password",
744
+ key: "clientSecret",
745
+ label: "Client Secret",
746
+ showToggle: true,
747
+ default: ""
748
+ },
749
+ {
750
+ type: "text",
751
+ key: "redirectUri",
752
+ label: "Redirect URI override",
753
+ description: "Optional — leave empty. Empty: a sign-in returns to the hub address it was started from (LAN, mesh or public, as listed on the Network page). Set: pins that one callback.",
754
+ default: ""
755
+ },
756
+ {
757
+ type: "text",
758
+ key: "scopes",
759
+ label: "Scopes",
760
+ description: "Space-separated.",
761
+ default: "openid profile email"
762
+ },
763
+ {
764
+ type: "select",
765
+ key: "usernameClaim",
766
+ label: "Username claim",
767
+ default: "preferred_username",
768
+ options: [
769
+ {
770
+ value: "preferred_username",
771
+ label: "preferred_username"
772
+ },
773
+ {
774
+ value: "email",
775
+ label: "email"
776
+ },
777
+ {
778
+ value: "sub",
779
+ label: "sub (user id)"
780
+ }
781
+ ]
782
+ }
783
+ ]
784
+ }] };
785
+ //#endregion
786
+ //#region src/oidc/oidc-connections.ts
787
+ /**
788
+ * Pure helpers for OIDC connection rows in `config.providers`.
789
+ */
790
+ var INSTANCE_ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
791
+ var DEFAULT_OIDC_PROVIDER = {
792
+ id: "default",
793
+ displayName: "OpenID Connect",
794
+ icon: "shield-check",
795
+ issuerUrl: "",
796
+ clientId: "",
797
+ clientSecret: "",
798
+ redirectUri: "",
799
+ scopes: "openid profile email",
800
+ usernameClaim: "preferred_username"
801
+ };
802
+ function findOidcProvider(config, id) {
803
+ return config.providers.find((p) => p.id === id) ?? null;
804
+ }
805
+ function connectionConfigured(row) {
806
+ const secret = typeof row.clientSecret === "string" ? row.clientSecret.trim() : "";
807
+ return row.clientId.trim() !== "" && secret !== "";
808
+ }
809
+ function clientSecretView(clientSecret, secrets, connectionId) {
810
+ if (require_dist.isSecretMarker(clientSecret)) return require_dist.toSecretFieldView(clientSecret);
811
+ const plain = typeof clientSecret === "string" ? clientSecret.trim() : "";
812
+ if (plain === "") return null;
813
+ if (secrets === void 0) return require_dist.toSecretFieldView(plain);
814
+ return {
815
+ $secret: secrets.ref(require_dist.globalSecretScope(), require_dist.arrayItemFieldPath("providers", connectionId, "clientSecret")),
816
+ v: 1,
817
+ set: true
818
+ };
819
+ }
820
+ function createOidcConnection(config, input) {
821
+ const id = input.id.trim();
822
+ if (!INSTANCE_ID_PATTERN.test(id)) return {
823
+ ok: false,
824
+ reason: "invalid-id"
825
+ };
826
+ if (config.providers.some((p) => p.id === id)) return {
827
+ ok: false,
828
+ reason: "duplicate-id"
829
+ };
830
+ const row = {
831
+ ...DEFAULT_OIDC_PROVIDER,
832
+ id,
833
+ displayName: input.displayName.trim() || DEFAULT_OIDC_PROVIDER.displayName
834
+ };
835
+ return {
836
+ ok: true,
837
+ id,
838
+ config: { providers: [...config.providers, row] }
839
+ };
840
+ }
841
+ function updateOidcConnection(config, id, patch) {
842
+ const idx = config.providers.findIndex((p) => p.id === id);
843
+ if (idx < 0) return {
844
+ ok: false,
845
+ reason: "not-found"
846
+ };
847
+ const prev = config.providers[idx];
848
+ if (prev === void 0) return {
849
+ ok: false,
850
+ reason: "not-found"
851
+ };
852
+ const next = {
853
+ ...prev,
854
+ displayName: patch.displayName.trim() || prev.displayName,
855
+ ...patch.icon !== void 0 ? { icon: patch.icon } : {},
856
+ ...patch.issuerUrl !== void 0 ? { issuerUrl: patch.issuerUrl } : {},
857
+ ...patch.clientId !== void 0 ? { clientId: patch.clientId } : {},
858
+ ...patch.clientSecret !== void 0 ? { clientSecret: patch.clientSecret } : {},
859
+ ...patch.redirectUri !== void 0 ? { redirectUri: patch.redirectUri } : {},
860
+ ...patch.scopes !== void 0 ? { scopes: patch.scopes } : {},
861
+ ...patch.usernameClaim !== void 0 ? { usernameClaim: patch.usernameClaim } : {}
862
+ };
863
+ return {
864
+ ok: true,
865
+ config: { providers: config.providers.map((p, i) => i === idx ? next : p) },
866
+ clearClientSecret: patch.clearClientSecret === true
867
+ };
868
+ }
869
+ function deleteOidcConnection(config, id) {
870
+ if (!config.providers.some((p) => p.id === id)) return {
871
+ ok: false,
872
+ reason: "not-found"
873
+ };
874
+ return {
875
+ ok: true,
876
+ config: { providers: config.providers.filter((p) => p.id !== id) }
877
+ };
878
+ }
879
+ /** Map a wire `clientSecret` field into an update patch fragment. */
880
+ function clientSecretPatchOf(value) {
881
+ if (value === void 0) return {};
882
+ if (require_dist.isSecretClear(value)) return { clearClientSecret: true };
883
+ if (value === "") return {};
884
+ return { clientSecret: value };
885
+ }
886
+ //#endregion
707
887
  //#region src/oidc/request-origin.ts
708
888
  /** host[:port] — a DNS name, IPv4 or bracketed IPv6. No userinfo, path or spaces. */
709
889
  var AUTHORITY_RE = /^(?:[a-z0-9.-]+|\[[0-9a-f:.]+\])(?::\d{1,5})?$/i;
@@ -797,6 +977,8 @@ function pickRequestOrigin(headers, allowed) {
797
977
  * `/<providerId>/callback` per configured provider. The handler
798
978
  * reads `:providerId` from the route params, picks the matching
799
979
  * config entry, and runs the OIDC flow against THAT IdP.
980
+ * - `oidc-connections` (singleton) — list / create / update / delete for
981
+ * IdP rows; Settings UI is DataTable + dialog (no editable-array).
800
982
  *
801
983
  * Each provider entry independently performs:
802
984
  * - PKCE S256 + nonce
@@ -819,17 +1001,7 @@ function pickRequestOrigin(headers, allowed) {
819
1001
  * - Refresh token rotation (offline_access).
820
1002
  * - Persist state + nonce + PKCE across restart (multi-replica).
821
1003
  */
822
- var DEFAULT_PROVIDER = {
823
- id: "default",
824
- displayName: "OpenID Connect",
825
- icon: "shield-check",
826
- issuerUrl: "",
827
- clientId: "",
828
- clientSecret: "",
829
- redirectUri: "",
830
- scopes: "openid profile email",
831
- usernameClaim: "preferred_username"
832
- };
1004
+ var DEFAULT_PROVIDER = DEFAULT_OIDC_PROVIDER;
833
1005
  var DEFAULT_CONFIG = { providers: [] };
834
1006
  var STATE_TTL_MS = 5 * 6e4;
835
1007
  /**
@@ -838,12 +1010,6 @@ var STATE_TTL_MS = 5 * 6e4;
838
1010
  * so a junk value is refused here rather than carried into a signed bridge.
839
1011
  */
840
1012
  var LINK_INTENT_PATTERN = /^[A-Za-z0-9_-]{16,128}$/;
841
- /**
842
- * An instance id appears in URLs and in the identity `oidc:<id>:<sub>`; a `:`
843
- * would make two identities read the same, so ids are slugs. A configured row
844
- * whose id is not one is skipped.
845
- */
846
- var INSTANCE_ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
847
1013
  /** Bound on in-flight logins: `/start` is public, so a flood must not grow the map. */
848
1014
  var MAX_PENDING_STATES = 1e3;
849
1015
  /**
@@ -865,9 +1031,14 @@ var AuthOidcAddon = class extends require_dist.BaseAddon {
865
1031
  /** Pending OAuth states across ALL providers. The pending entry
866
1032
  * carries `providerId` so the /callback handler picks the right config. */
867
1033
  pendingStates = /* @__PURE__ */ new Map();
1034
+ /** Keychain path for each IdP's client secret (D787 / D828 sibling). */
1035
+ secretStatePaths = ["providers[id].clientSecret"];
868
1036
  constructor() {
869
1037
  super({ ...DEFAULT_CONFIG });
870
1038
  }
1039
+ async onConfigChanged() {
1040
+ this.rebuildInstances();
1041
+ }
871
1042
  async onInitialize() {
872
1043
  this.rebuildInstances();
873
1044
  const authProvider = {
@@ -914,9 +1085,84 @@ var AuthOidcAddon = class extends require_dist.BaseAddon {
914
1085
  {
915
1086
  capability: require_dist.loginMethodCapability,
916
1087
  provider: loginMethodProvider
1088
+ },
1089
+ {
1090
+ capability: require_dist.oidcConnectionsCapability,
1091
+ provider: this.connectionsProvider()
917
1092
  }
918
1093
  ];
919
1094
  }
1095
+ connectionsProvider() {
1096
+ return {
1097
+ connectionFormSchema: async () => OIDC_CONNECTION_FORM_SCHEMA,
1098
+ listConnections: async () => {
1099
+ const secrets = this.ctx.secrets;
1100
+ return this.config.providers.map((row) => {
1101
+ const merged = {
1102
+ ...DEFAULT_PROVIDER,
1103
+ ...row
1104
+ };
1105
+ return {
1106
+ id: merged.id,
1107
+ displayName: merged.displayName,
1108
+ icon: require_dist.isDisplayIconKey(merged.icon) ? merged.icon : DEFAULT_OIDC_ICON,
1109
+ issuerUrl: merged.issuerUrl,
1110
+ clientId: merged.clientId,
1111
+ configured: connectionConfigured(merged),
1112
+ formValues: {
1113
+ displayName: merged.displayName,
1114
+ icon: merged.icon,
1115
+ issuerUrl: merged.issuerUrl,
1116
+ clientId: merged.clientId,
1117
+ clientSecret: clientSecretView(merged.clientSecret, secrets, merged.id) ?? "",
1118
+ redirectUri: merged.redirectUri,
1119
+ scopes: merged.scopes,
1120
+ usernameClaim: merged.usernameClaim
1121
+ }
1122
+ };
1123
+ });
1124
+ },
1125
+ createConnection: async (input) => {
1126
+ const result = createOidcConnection(this.config, input);
1127
+ if (!result.ok) throw new Error(result.reason === "duplicate-id" ? `An OIDC connection with id "${input.id}" already exists` : `Invalid connection id "${input.id}" — use a lowercase slug`);
1128
+ await this.updateGlobalSettings(result.config);
1129
+ this.rebuildInstances();
1130
+ return { id: result.id };
1131
+ },
1132
+ updateConnection: async (input) => {
1133
+ const secretPatch = clientSecretPatchOf(input.clientSecret);
1134
+ const result = updateOidcConnection(this.config, input.id, {
1135
+ displayName: input.displayName,
1136
+ ...input.icon !== void 0 ? { icon: input.icon } : {},
1137
+ ...input.issuerUrl !== void 0 ? { issuerUrl: input.issuerUrl } : {},
1138
+ ...input.clientId !== void 0 ? { clientId: input.clientId } : {},
1139
+ ...secretPatch,
1140
+ ...input.redirectUri !== void 0 ? { redirectUri: input.redirectUri } : {},
1141
+ ...input.scopes !== void 0 ? { scopes: input.scopes } : {},
1142
+ ...input.usernameClaim !== void 0 ? { usernameClaim: input.usernameClaim } : {}
1143
+ });
1144
+ if (!result.ok) throw new Error(`Unknown OIDC connection "${input.id}"`);
1145
+ if (result.clearClientSecret) {
1146
+ const cleared = result.config.providers.map((p) => p.id === input.id ? {
1147
+ ...p,
1148
+ clientSecret: require_dist.SECRET_CLEAR
1149
+ } : p);
1150
+ await this.updateGlobalSettings({ providers: cleared });
1151
+ } else await this.updateGlobalSettings(result.config);
1152
+ this.rebuildInstances();
1153
+ return { ok: true };
1154
+ },
1155
+ deleteConnection: async (input) => {
1156
+ if (findOidcProvider(this.config, input.id) === null) throw new Error(`Unknown OIDC connection "${input.id}"`);
1157
+ const result = deleteOidcConnection(this.config, input.id);
1158
+ if (!result.ok) throw new Error(`Unknown OIDC connection "${input.id}"`);
1159
+ await this.updateGlobalSettings(result.config);
1160
+ await this.clearSecrets([`providers[${input.id}].clientSecret`]);
1161
+ this.rebuildInstances();
1162
+ return { ok: true };
1163
+ }
1164
+ };
1165
+ }
920
1166
  /**
921
1167
  * Build one `redirect` login-method per configured provider instance.
922
1168
  * `startUrl` is the addon's public `/start` route for that instance;
@@ -941,92 +1187,9 @@ var AuthOidcAddon = class extends require_dist.BaseAddon {
941
1187
  globalSettingsSchema() {
942
1188
  return this.schema({ sections: [{
943
1189
  id: "oidc",
944
- title: "OIDC Providers",
945
- description: "Configure one or more IdPs (Google, Microsoft, Okta, Keycloak, …). Each entry produces an independent login button. The redirect URI shown on the IdP-side must include the provider id in the path: `<origin>/addon/auth-oidc/<id>/callback`.",
946
- columns: 1,
947
- fields: [this.field({
948
- type: "editable-array",
949
- key: "providers",
950
- label: "Providers",
951
- description: "Each row is a distinct OIDC IdP. Click + to add.",
952
- default: [],
953
- itemFields: [
954
- {
955
- type: "text",
956
- key: "id",
957
- label: "Instance id",
958
- description: "URL-friendly slug — appears in the redirect URI as /addon/auth-oidc/<id>/callback. Stable; renaming breaks any IdP-side registrations.",
959
- default: ""
960
- },
961
- {
962
- type: "text",
963
- key: "displayName",
964
- label: "Display name",
965
- description: "Shown on the login button.",
966
- default: "OpenID Connect"
967
- },
968
- {
969
- type: "icon",
970
- key: "icon",
971
- label: "Icon",
972
- description: "Shown on the login button.",
973
- default: DEFAULT_PROVIDER.icon
974
- },
975
- {
976
- type: "text",
977
- key: "issuerUrl",
978
- label: "Issuer URL",
979
- description: "IdP base URL — discovery doc lives at <issuer>/.well-known/openid-configuration.",
980
- default: ""
981
- },
982
- {
983
- type: "text",
984
- key: "clientId",
985
- label: "Client ID",
986
- default: ""
987
- },
988
- {
989
- type: "password",
990
- key: "clientSecret",
991
- label: "Client Secret",
992
- default: ""
993
- },
994
- {
995
- type: "text",
996
- key: "redirectUri",
997
- label: "Redirect URI override",
998
- description: "Optional — leave empty. Empty: a sign-in returns to the hub address it was started from (LAN, mesh or public, as listed on the Network page), so register one callback per address you sign in from at the IdP. Set: it PINS that one callback — every sign-in returns to its address, wherever it started.",
999
- default: ""
1000
- },
1001
- {
1002
- type: "text",
1003
- key: "scopes",
1004
- label: "Scopes",
1005
- description: "Space-separated.",
1006
- default: "openid profile email"
1007
- },
1008
- {
1009
- type: "select",
1010
- key: "usernameClaim",
1011
- label: "Username claim",
1012
- default: "preferred_username",
1013
- options: [
1014
- {
1015
- value: "preferred_username",
1016
- label: "preferred_username"
1017
- },
1018
- {
1019
- value: "email",
1020
- label: "email"
1021
- },
1022
- {
1023
- value: "sub",
1024
- label: "sub (user id)"
1025
- }
1026
- ]
1027
- }
1028
- ]
1029
- })]
1190
+ title: "OpenID Connect",
1191
+ description: "Manage IdP connections in this page’s Settings table (Add / Edit). Each connection’s redirect URI is `<origin>/addon/auth-oidc/<id>/callback`. Credentials stay in the CamStack keychain.",
1192
+ fields: []
1030
1193
  }] });
1031
1194
  }
1032
1195
  rebuildInstances() {