@chipmobilesdk/rn-auth 0.5.0 → 0.6.0

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.
Files changed (167) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/README.md +8 -5
  3. package/lib/commonjs/access/accessTier.js +111 -0
  4. package/lib/commonjs/access/accessTier.js.map +1 -0
  5. package/lib/commonjs/app-auth.js +13 -0
  6. package/lib/commonjs/app-auth.js.map +1 -0
  7. package/lib/commonjs/config/types.js +50 -0
  8. package/lib/commonjs/config/types.js.map +1 -0
  9. package/lib/commonjs/config/validateConfig.js +114 -0
  10. package/lib/commonjs/config/validateConfig.js.map +1 -0
  11. package/lib/commonjs/core/authMachine.js +406 -0
  12. package/lib/commonjs/core/authMachine.js.map +1 -0
  13. package/lib/commonjs/core/profile.js +59 -0
  14. package/lib/commonjs/core/profile.js.map +1 -0
  15. package/lib/commonjs/core/session.js +125 -0
  16. package/lib/commonjs/core/session.js.map +1 -0
  17. package/lib/commonjs/diagnostics/errors.js +83 -0
  18. package/lib/commonjs/diagnostics/errors.js.map +1 -0
  19. package/lib/commonjs/diagnostics/messageKeys.js +51 -0
  20. package/lib/commonjs/diagnostics/messageKeys.js.map +1 -0
  21. package/lib/commonjs/index.js +175 -0
  22. package/lib/commonjs/index.js.map +1 -0
  23. package/lib/commonjs/keychain.js +13 -0
  24. package/lib/commonjs/keychain.js.map +1 -0
  25. package/lib/commonjs/oidc/authClient.js +157 -0
  26. package/lib/commonjs/oidc/authClient.js.map +1 -0
  27. package/lib/commonjs/oidc/classifyError.js +65 -0
  28. package/lib/commonjs/oidc/classifyError.js.map +1 -0
  29. package/lib/commonjs/oidc/socialRouting.js +58 -0
  30. package/lib/commonjs/oidc/socialRouting.js.map +1 -0
  31. package/lib/commonjs/package.json +1 -0
  32. package/lib/commonjs/react/AuthProvider.js +37 -0
  33. package/lib/commonjs/react/AuthProvider.js.map +1 -0
  34. package/lib/commonjs/react/hooks.js +122 -0
  35. package/lib/commonjs/react/hooks.js.map +1 -0
  36. package/lib/commonjs/testing/conformance.js +148 -0
  37. package/lib/commonjs/testing/conformance.js.map +1 -0
  38. package/lib/commonjs/testing/index.js +53 -0
  39. package/lib/commonjs/testing/index.js.map +1 -0
  40. package/lib/commonjs/tokens/accessToken.js +165 -0
  41. package/lib/commonjs/tokens/accessToken.js.map +1 -0
  42. package/lib/commonjs/tokens/secureStore.js +60 -0
  43. package/lib/commonjs/tokens/secureStore.js.map +1 -0
  44. package/lib/module/access/accessTier.js +106 -0
  45. package/lib/module/access/accessTier.js.map +1 -0
  46. package/lib/module/app-auth.js +9 -0
  47. package/lib/module/app-auth.js.map +1 -0
  48. package/lib/module/config/types.js +46 -0
  49. package/lib/module/config/types.js.map +1 -0
  50. package/lib/module/config/validateConfig.js +110 -0
  51. package/lib/module/config/validateConfig.js.map +1 -0
  52. package/lib/module/core/authMachine.js +402 -0
  53. package/lib/module/core/authMachine.js.map +1 -0
  54. package/lib/module/core/profile.js +54 -0
  55. package/lib/module/core/profile.js.map +1 -0
  56. package/lib/module/core/session.js +118 -0
  57. package/lib/module/core/session.js.map +1 -0
  58. package/lib/module/diagnostics/errors.js +74 -0
  59. package/lib/module/diagnostics/errors.js.map +1 -0
  60. package/lib/module/diagnostics/messageKeys.js +46 -0
  61. package/lib/module/diagnostics/messageKeys.js.map +1 -0
  62. package/lib/module/index.js +33 -0
  63. package/lib/module/index.js.map +1 -0
  64. package/lib/module/keychain.js +9 -0
  65. package/lib/module/keychain.js.map +1 -0
  66. package/lib/module/oidc/authClient.js +152 -0
  67. package/lib/module/oidc/authClient.js.map +1 -0
  68. package/lib/module/oidc/classifyError.js +60 -0
  69. package/lib/module/oidc/classifyError.js.map +1 -0
  70. package/lib/module/oidc/socialRouting.js +52 -0
  71. package/lib/module/oidc/socialRouting.js.map +1 -0
  72. package/lib/module/package.json +1 -0
  73. package/lib/module/react/AuthProvider.js +31 -0
  74. package/lib/module/react/AuthProvider.js.map +1 -0
  75. package/lib/module/react/hooks.js +111 -0
  76. package/lib/module/react/hooks.js.map +1 -0
  77. package/lib/module/testing/conformance.js +140 -0
  78. package/lib/module/testing/conformance.js.map +1 -0
  79. package/lib/module/testing/index.js +25 -0
  80. package/lib/module/testing/index.js.map +1 -0
  81. package/lib/module/tokens/accessToken.js +161 -0
  82. package/lib/module/tokens/accessToken.js.map +1 -0
  83. package/lib/module/tokens/secureStore.js +56 -0
  84. package/lib/module/tokens/secureStore.js.map +1 -0
  85. package/lib/typescript/commonjs/access/accessTier.d.ts +14 -0
  86. package/lib/typescript/commonjs/access/accessTier.d.ts.map +1 -0
  87. package/lib/typescript/commonjs/app-auth.d.ts +7 -0
  88. package/lib/typescript/commonjs/app-auth.d.ts.map +1 -0
  89. package/lib/typescript/commonjs/config/types.d.ts +171 -0
  90. package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
  91. package/lib/typescript/commonjs/config/validateConfig.d.ts +8 -0
  92. package/lib/typescript/commonjs/config/validateConfig.d.ts.map +1 -0
  93. package/lib/typescript/commonjs/core/authMachine.d.ts +14 -0
  94. package/lib/typescript/commonjs/core/authMachine.d.ts.map +1 -0
  95. package/lib/typescript/commonjs/core/profile.d.ts +15 -0
  96. package/lib/typescript/commonjs/core/profile.d.ts.map +1 -0
  97. package/lib/typescript/commonjs/core/session.d.ts +60 -0
  98. package/lib/typescript/commonjs/core/session.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/diagnostics/errors.d.ts +37 -0
  100. package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts +57 -0
  102. package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/index.d.ts +27 -0
  104. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/keychain.d.ts +7 -0
  106. package/lib/typescript/commonjs/keychain.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/oidc/authClient.d.ts +75 -0
  108. package/lib/typescript/commonjs/oidc/authClient.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/oidc/classifyError.d.ts +28 -0
  110. package/lib/typescript/commonjs/oidc/classifyError.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/oidc/socialRouting.d.ts +22 -0
  112. package/lib/typescript/commonjs/oidc/socialRouting.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/package.json +1 -0
  114. package/lib/typescript/commonjs/react/AuthProvider.d.ts +17 -0
  115. package/lib/typescript/commonjs/react/AuthProvider.d.ts.map +1 -0
  116. package/lib/typescript/commonjs/react/hooks.d.ts +42 -0
  117. package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
  118. package/lib/typescript/commonjs/testing/conformance.d.ts +32 -0
  119. package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
  120. package/lib/typescript/commonjs/testing/index.d.ts +11 -0
  121. package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
  122. package/lib/typescript/commonjs/tokens/accessToken.d.ts +45 -0
  123. package/lib/typescript/commonjs/tokens/accessToken.d.ts.map +1 -0
  124. package/lib/typescript/commonjs/tokens/secureStore.d.ts +26 -0
  125. package/lib/typescript/commonjs/tokens/secureStore.d.ts.map +1 -0
  126. package/lib/typescript/module/access/accessTier.d.ts +14 -0
  127. package/lib/typescript/module/access/accessTier.d.ts.map +1 -0
  128. package/lib/typescript/module/app-auth.d.ts +7 -0
  129. package/lib/typescript/module/app-auth.d.ts.map +1 -0
  130. package/lib/typescript/module/config/types.d.ts +171 -0
  131. package/lib/typescript/module/config/types.d.ts.map +1 -0
  132. package/lib/typescript/module/config/validateConfig.d.ts +8 -0
  133. package/lib/typescript/module/config/validateConfig.d.ts.map +1 -0
  134. package/lib/typescript/module/core/authMachine.d.ts +14 -0
  135. package/lib/typescript/module/core/authMachine.d.ts.map +1 -0
  136. package/lib/typescript/module/core/profile.d.ts +15 -0
  137. package/lib/typescript/module/core/profile.d.ts.map +1 -0
  138. package/lib/typescript/module/core/session.d.ts +60 -0
  139. package/lib/typescript/module/core/session.d.ts.map +1 -0
  140. package/lib/typescript/module/diagnostics/errors.d.ts +37 -0
  141. package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
  142. package/lib/typescript/module/diagnostics/messageKeys.d.ts +57 -0
  143. package/lib/typescript/module/diagnostics/messageKeys.d.ts.map +1 -0
  144. package/lib/typescript/module/index.d.ts +27 -0
  145. package/lib/typescript/module/index.d.ts.map +1 -0
  146. package/lib/typescript/module/keychain.d.ts +7 -0
  147. package/lib/typescript/module/keychain.d.ts.map +1 -0
  148. package/lib/typescript/module/oidc/authClient.d.ts +75 -0
  149. package/lib/typescript/module/oidc/authClient.d.ts.map +1 -0
  150. package/lib/typescript/module/oidc/classifyError.d.ts +28 -0
  151. package/lib/typescript/module/oidc/classifyError.d.ts.map +1 -0
  152. package/lib/typescript/module/oidc/socialRouting.d.ts +22 -0
  153. package/lib/typescript/module/oidc/socialRouting.d.ts.map +1 -0
  154. package/lib/typescript/module/package.json +1 -0
  155. package/lib/typescript/module/react/AuthProvider.d.ts +17 -0
  156. package/lib/typescript/module/react/AuthProvider.d.ts.map +1 -0
  157. package/lib/typescript/module/react/hooks.d.ts +42 -0
  158. package/lib/typescript/module/react/hooks.d.ts.map +1 -0
  159. package/lib/typescript/module/testing/conformance.d.ts +32 -0
  160. package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
  161. package/lib/typescript/module/testing/index.d.ts +11 -0
  162. package/lib/typescript/module/testing/index.d.ts.map +1 -0
  163. package/lib/typescript/module/tokens/accessToken.d.ts +45 -0
  164. package/lib/typescript/module/tokens/accessToken.d.ts.map +1 -0
  165. package/lib/typescript/module/tokens/secureStore.d.ts +26 -0
  166. package/lib/typescript/module/tokens/secureStore.d.ts.map +1 -0
  167. package/package.json +68 -21
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Access-tier evaluation (FR-010/FR-011/FR-019/FR-020, R6).
5
+ *
6
+ * Pure function over the authenticated token's claims and the app-specific
7
+ * mapping. Object ids are authoritative; display names never grant access.
8
+ * Missing, stale, ambiguous, or group-overage claims fail closed (premium
9
+ * denied, verification = 'unverified').
10
+ */
11
+
12
+ /** The fail-closed default: free + unverified. */
13
+ export function failClosedTier() {
14
+ return {
15
+ tier: 'free',
16
+ source: 'default',
17
+ verification: 'unverified'
18
+ };
19
+ }
20
+ function toStringArray(value) {
21
+ if (Array.isArray(value)) {
22
+ return value.filter(entry => typeof entry === 'string');
23
+ }
24
+ if (typeof value === 'string') {
25
+ return [value];
26
+ }
27
+ return [];
28
+ }
29
+
30
+ /**
31
+ * Entra emits a groups overage indicator (`_claim_names.groups` or `hasgroups`)
32
+ * instead of inline groups when the list is too large. Reading the full list
33
+ * would require Graph (out of scope, FR-012), so overage fails closed.
34
+ */
35
+ function hasGroupOverage(claims) {
36
+ if (claims.hasgroups === true) {
37
+ return true;
38
+ }
39
+ const claimNames = claims._claim_names;
40
+ if (claimNames && typeof claimNames === 'object' && 'groups' in claimNames) {
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+ function matchesClaim(claims, matcher) {
46
+ const value = claims[matcher.claim];
47
+ if (Array.isArray(value)) {
48
+ return value.includes(matcher.equals);
49
+ }
50
+ return value === matcher.equals;
51
+ }
52
+
53
+ /** Evaluate the access tier, failing closed when entitlement is unverifiable. */
54
+ export function evaluateAccessTier(claims, mapping, now = Date.now()) {
55
+ // Object ids first (authoritative). Display names are never consulted.
56
+ const groups = toStringArray(claims.groups);
57
+ if (mapping.premiumGroupObjectIds.length > 0 && groups.some(group => mapping.premiumGroupObjectIds.includes(group))) {
58
+ return {
59
+ tier: 'premium',
60
+ source: 'group',
61
+ verification: 'verified',
62
+ lastRefreshAt: now
63
+ };
64
+ }
65
+
66
+ // Roles next.
67
+ const roles = toStringArray(claims.roles);
68
+ if (mapping.premiumRoleNames?.length && roles.some(role => mapping.premiumRoleNames.includes(role))) {
69
+ return {
70
+ tier: 'premium',
71
+ source: 'role',
72
+ verification: 'verified',
73
+ lastRefreshAt: now
74
+ };
75
+ }
76
+
77
+ // Custom claim matchers last.
78
+ if (mapping.premiumClaimMatchers?.some(matcher => matchesClaim(claims, matcher))) {
79
+ return {
80
+ tier: 'premium',
81
+ source: 'claim',
82
+ verification: 'verified',
83
+ lastRefreshAt: now
84
+ };
85
+ }
86
+
87
+ // No premium indicator matched. If group claims are unavailable due to
88
+ // overage and premium depends on groups, we cannot verify → fail closed.
89
+ if (mapping.premiumGroupObjectIds.length > 0 && hasGroupOverage(claims)) {
90
+ return {
91
+ tier: 'free',
92
+ source: 'default',
93
+ verification: 'unverified',
94
+ lastRefreshAt: now
95
+ };
96
+ }
97
+
98
+ // Verified free: claims were present and simply did not grant premium.
99
+ return {
100
+ tier: 'free',
101
+ source: 'default',
102
+ verification: 'verified',
103
+ lastRefreshAt: now
104
+ };
105
+ }
106
+ //# sourceMappingURL=accessTier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["failClosedTier","tier","source","verification","toStringArray","value","Array","isArray","filter","entry","hasGroupOverage","claims","hasgroups","claimNames","_claim_names","matchesClaim","matcher","claim","includes","equals","evaluateAccessTier","mapping","now","Date","groups","premiumGroupObjectIds","length","some","group","lastRefreshAt","roles","premiumRoleNames","role","premiumClaimMatchers"],"sourceRoot":"../../../src","sources":["access/accessTier.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA,OAAO,SAASA,cAAcA,CAAA,EAAe;EAC5C,OAAO;IAAEC,IAAI,EAAE,MAAM;IAAEC,MAAM,EAAE,SAAS;IAAEC,YAAY,EAAE;EAAa,CAAC;AACvE;AAEA,SAASC,aAAaA,CAACC,KAAc,EAAY;EAChD,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;IACzB,OAAOA,KAAK,CAACG,MAAM,CAAEC,KAAK,IAAsB,OAAOA,KAAK,KAAK,QAAQ,CAAC;EAC3E;EACA,IAAI,OAA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,KAAK,CAAC;EACzC,IACCT,OAAO,CAACU,gBAAgB,EAAEL,MAAM,IAChCI,KAAK,CAACH,IAAI,CAACK,IAAI,IAAIX,OAAO,CAACU,gBAAgB,CAAEb,QAAQ,CAACc,IAAI,CAAC,CAAC,EAC3D;IACD,OAAO;MAAE/B,IAAI,EAAE,SAAS;MAAEC,MAAM,EAAE,MAAM;MAAEC,YAAY,EAAE,UAAU;MAAE0B,aAAa,EAAEP;IAAI,CAAC;EACzF;;EAEA;EACA,IAAID,OAAO,CAACY,oBAAoB,EAAEN,IAAI,CAACX,OAAO,IAAID,YAAY,CAACJ,MAAM,EAAEK,OAAO,CAAC,CAAC,EAAE;IACjF,OAAO;MAAEf,IAAI,EAAE,SAAS;MAAEC,MAAM,EAAE,OAAO;MAAEC,YAAY,EAAE,UAAU;MAAE0B,aAAa,EAAEP;IAAI,CAAC;EAC1F;;EAEA;EACA;EACA,IAAID,OAAO,CAACI,qBAAqB,CAACC,MAAM,GAAG,CAAC,IAAIhB,eAAe,CAACC,MAAM,CAAC,EAAE;IACxE,OAAO;MAAEV,IAAI,EAAE,MAAM;MAAEC,MAAM,EAAE,SAAS;MAAEC,YAAY,EAAE,YAAY;MAAE0B,aAAa,EAAEP;IAAI,CAAC;EAC3F;;EAEA;EACA,OAAO;IAAErB,IAAI,EAAE,MAAM;IAAEC,MAAM,EAAE,SAAS;IAAEC,YAAY,EAAE,UAAU;IAAE0B,aAAa,EAAEP;EAAI,CAAC;AACzF","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * `@chipmobilesdk/rn-auth/app-auth`: the default OIDC client over
5
+ * react-native-app-auth (AUTH-09). Its own entrypoint, so an app that injects its
6
+ * own client never reaches this module.
7
+ */
8
+ export { createAppAuthClient } from "./oidc/authClient.js";
9
+ //# sourceMappingURL=app-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAppAuthClient"],"sourceRoot":"../../src","sources":["app-auth.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA,SAASA,mBAAmB,QAAmC,sBAAmB","ignoreList":[]}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Public type contracts for @chipmobilesdk/rn-auth. Shapes follow
5
+ * specs/003-mobile-entra-auth/data-model.md.
6
+ */
7
+
8
+ /** The providers this package has copy for out of the box. */
9
+
10
+ /**
11
+ * A provider id. Open on purpose: routing is `domain_hint` and nothing else, so
12
+ * adding an IdP the tenant federates — Microsoft account, an email one-time
13
+ * code — is a change to an app's config, not a release of this package
14
+ * (AUTH-14). `KnownProviderId` keeps the three familiar ones in autocomplete.
15
+ */
16
+
17
+ export const DEVICE_PLATFORMS = ['ios', 'android'];
18
+
19
+ /** Provider Setup Configuration — non-secret public values only (FR-016/FR-017). */
20
+
21
+ /** One configured protected resource for delegated token requests (FR-007). */
22
+
23
+ /** App-specific mapping from tenant indicators to access tiers (FR-019/FR-020). */
24
+
25
+ /** App-supplied, public-only setup input (FR-015/FR-016/FR-017). */
26
+
27
+ /** Advanced/testing options. `platform` overrides the detected device platform. */
28
+
29
+ /** Customer User / app-visible profile (FR-006). */
30
+
31
+ /** Access Tier — local interpretation of tenant indicators (FR-010). */
32
+
33
+ /** Access Token Request result (FR-007). */
34
+
35
+ /** Single active app-visible authenticated state (FR-005/FR-022). */
36
+
37
+ /** Result of a premium-only gate check (US3). */
38
+
39
+ /**
40
+ * What `signOutGlobal` did beyond the device (added in 0.2.2). Local state is
41
+ * cleared either way; `failed` means the tenant session may still be alive, so
42
+ * the next interactive sign-in can complete without a password prompt.
43
+ */
44
+
45
+ /** The auth controller returned by `createAuth` (single active account). */
46
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEVICE_PLATFORMS"],"sourceRoot":"../../../src","sources":["config/types.ts"],"mappings":";;AAAA;AACA;AACA;AACA;;AAQA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,MAAMA,gBAA2C,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC;;AAE7E;;AAoBA;;AAYA;;AAUA;;AAmBA;;AAiBA;;AAoBA;;AAUA;;AASA;;AASA;;AAMA;AACA;AACA;AACA;AACA;;AAOA","ignoreList":[]}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Deterministic configuration validation (FR-005 → configuration-error).
5
+ * Throws AuthConfigError before any provider flow can start (US4 scenario 2).
6
+ * Covers the auth-config.md Section A–F rules.
7
+ */
8
+
9
+ import { DEVICE_PLATFORMS } from "./types.js";
10
+ import { AuthConfigError } from "../diagnostics/errors.js";
11
+ function hasScheme(url) {
12
+ return /^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(url);
13
+ }
14
+
15
+ /** https, or http on a development machine. */
16
+ function isSecureAuthority(url) {
17
+ if (/^https:/i.test(url)) {
18
+ return true;
19
+ }
20
+ return /^http:\/\/(localhost|127\.0\.0\.1|\[::1\])(:\d+)?(\/|$)/i.test(url);
21
+ }
22
+ export function validateConfig(config) {
23
+ // Section A — tenant/client settings
24
+ if (!config.authority || !config.authority.trim()) {
25
+ throw new AuthConfigError('auth.error.configuration', 'Missing "authority"');
26
+ }
27
+ if (!hasScheme(config.authority)) {
28
+ throw new AuthConfigError('auth.error.configuration', '"authority" must be an absolute URL');
29
+ }
30
+ // Tokens travel over this. A tenant reachable over plaintext http is a
31
+ // configuration mistake, not a deployment choice — except on a dev machine.
32
+ if (!isSecureAuthority(config.authority)) {
33
+ throw new AuthConfigError('auth.error.configuration', '"authority" must use https (http is accepted only for localhost)');
34
+ }
35
+ if (!config.clientId || !config.clientId.trim()) {
36
+ throw new AuthConfigError('auth.error.configuration', 'Missing "clientId"');
37
+ }
38
+ if (!config.redirectUrl || !config.redirectUrl.trim()) {
39
+ throw new AuthConfigError('auth.error.configuration', 'Missing "redirectUrl"');
40
+ }
41
+ if (!hasScheme(config.redirectUrl)) {
42
+ throw new AuthConfigError('auth.error.redirectMismatch', '"redirectUrl" must include a scheme matching the native redirect configuration');
43
+ }
44
+ if (!Array.isArray(config.scopes) || config.scopes.length === 0) {
45
+ throw new AuthConfigError('auth.error.configuration', 'At least one OIDC scope is required');
46
+ }
47
+ if (!config.scopes.includes('offline_access')) {
48
+ throw new AuthConfigError('auth.error.configuration', '"offline_access" scope is required for session restore and silent refresh');
49
+ }
50
+
51
+ // Sections B/C — providers
52
+ if (!Array.isArray(config.providers) || config.providers.length === 0) {
53
+ throw new AuthConfigError('auth.error.configuration', 'At least one provider must be configured');
54
+ }
55
+ const providerIds = new Set();
56
+ for (const provider of config.providers) {
57
+ if (providerIds.has(provider.id)) {
58
+ throw new AuthConfigError('auth.error.configuration', `Duplicate provider "${provider.id}"`);
59
+ }
60
+ providerIds.add(provider.id);
61
+ if (!provider.domainHint || !provider.domainHint.trim()) {
62
+ throw new AuthConfigError('auth.error.configuration', `Provider "${provider.id}" is missing a domainHint`);
63
+ }
64
+ if (!Array.isArray(provider.platforms) || provider.platforms.length === 0) {
65
+ throw new AuthConfigError('auth.error.configuration', `Provider "${provider.id}" must declare at least one platform`);
66
+ }
67
+ for (const platform of provider.platforms) {
68
+ if (!DEVICE_PLATFORMS.includes(platform)) {
69
+ // A typo here hides the provider on every device rather than failing.
70
+ throw new AuthConfigError('auth.error.configuration', `Provider "${provider.id}" declares unknown platform "${String(platform)}"`);
71
+ }
72
+ }
73
+ if (typeof provider.labelKey !== 'string' || !provider.labelKey.trim()) {
74
+ throw new AuthConfigError('auth.error.configuration', `Provider "${provider.id}" is missing a labelKey`);
75
+ }
76
+ }
77
+
78
+ // Section D — resources
79
+ if (config.resources) {
80
+ const resourceKeys = new Set();
81
+ for (const resource of config.resources) {
82
+ if (!resource.key || !resource.key.trim()) {
83
+ throw new AuthConfigError('auth.error.configuration', 'A resource is missing "key"');
84
+ }
85
+ if (resourceKeys.has(resource.key)) {
86
+ throw new AuthConfigError('auth.error.configuration', `Duplicate resource "${resource.key}"`);
87
+ }
88
+ resourceKeys.add(resource.key);
89
+ if (!Array.isArray(resource.scopes) || resource.scopes.length === 0) {
90
+ throw new AuthConfigError('auth.error.configuration', `Resource "${resource.key}" must declare at least one scope`);
91
+ }
92
+ }
93
+ }
94
+
95
+ // Section E — access-tier mapping
96
+ const mapping = config.accessTierMapping;
97
+ if (!mapping) {
98
+ throw new AuthConfigError('auth.error.configuration', 'Missing "accessTierMapping"');
99
+ }
100
+ const hasPremiumIndicator = (mapping.premiumGroupObjectIds?.length ?? 0) > 0 || (mapping.premiumRoleNames?.length ?? 0) > 0 || (mapping.premiumClaimMatchers?.length ?? 0) > 0;
101
+ if (!hasPremiumIndicator) {
102
+ throw new AuthConfigError('auth.error.configuration', 'accessTierMapping must define at least one premium group object id, role name, or claim matcher');
103
+ }
104
+
105
+ // Section F — injected ports
106
+ if (!config.secureStore) {
107
+ throw new AuthConfigError('auth.error.configuration', 'A secureStore is required (FR-021)');
108
+ }
109
+ }
110
+ //# sourceMappingURL=validateConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DEVICE_PLATFORMS","AuthConfigError","hasScheme","url","test","isSecureAuthority","validateConfig","config","authority","trim","clientId","redirectUrl","Array","isArray","scopes","length","includes","providers","providerIds","Set","provider","has","id","add","domainHint","platforms","platform","String","labelKey","resources","resourceKeys","resource","key","mapping","accessTierMapping","hasPremiumIndicator","premiumGroupObjectIds","premiumRoleNames","premiumClaimMatchers","secureStore"],"sourceRoot":"../../../src","sources":["config/validateConfig.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,gBAAgB,QAAyB,YAAS;AAC3D,SAASC,eAAe,QAAQ,0BAAuB;AAEvD,SAASC,SAASA,CAACC,GAAW,EAAW;EACxC,OAAO,2BAA2B,CAACC,IAAI,CAACD,GAAG,CAAC;AAC7C;;AAEA;AACA,SAASE,iBAAiBA,CAACF,GAAW,EAAW;EAChD,IAAI,UAAU,CAACC,IAAI,CAACD,GAAG,CAAC,EAAE;IACzB,OAAO,IAAI;EACZ;EACA,O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