@react-native-firebase/auth 24.1.1 → 25.0.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 (216) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/android/src/main/java/io/invertase/firebase/auth/ReactNativeFirebaseAuthModule.java +16 -4
  3. package/dist/module/ActionCodeURL.js +140 -0
  4. package/dist/module/ActionCodeURL.js.map +1 -0
  5. package/{lib → dist/module}/ConfirmationResult.js +4 -5
  6. package/dist/module/ConfirmationResult.js.map +1 -0
  7. package/{lib → dist/module}/MultiFactorResolver.js +14 -5
  8. package/dist/module/MultiFactorResolver.js.map +1 -0
  9. package/{lib → dist/module}/PhoneAuthListener.js +52 -75
  10. package/dist/module/PhoneAuthListener.js.map +1 -0
  11. package/dist/module/PhoneAuthState.js +25 -0
  12. package/dist/module/PhoneAuthState.js.map +1 -0
  13. package/dist/module/PhoneMultiFactorGenerator.js +39 -0
  14. package/dist/module/PhoneMultiFactorGenerator.js.map +1 -0
  15. package/{lib → dist/module}/Settings.js +3 -7
  16. package/dist/module/Settings.js.map +1 -0
  17. package/{lib → dist/module}/TotpMultiFactorGenerator.js +20 -15
  18. package/dist/module/TotpMultiFactorGenerator.js.map +1 -0
  19. package/{lib → dist/module}/TotpSecret.js +7 -5
  20. package/dist/module/TotpSecret.js.map +1 -0
  21. package/dist/module/User.js +245 -0
  22. package/dist/module/User.js.map +1 -0
  23. package/dist/module/constants.js +54 -0
  24. package/dist/module/constants.js.map +1 -0
  25. package/dist/module/credentials/AuthCredential.js +51 -0
  26. package/dist/module/credentials/AuthCredential.js.map +1 -0
  27. package/dist/module/credentials/EmailAuthCredential.js +51 -0
  28. package/dist/module/credentials/EmailAuthCredential.js.map +1 -0
  29. package/dist/module/credentials/OAuthCredential.js +84 -0
  30. package/dist/module/credentials/OAuthCredential.js.map +1 -0
  31. package/dist/module/credentials/PhoneAuthCredential.js +50 -0
  32. package/dist/module/credentials/PhoneAuthCredential.js.map +1 -0
  33. package/{lib/providers/GoogleAuthProvider.js → dist/module/credentials/index.js} +7 -19
  34. package/dist/module/credentials/index.js.map +1 -0
  35. package/{lib → dist/module}/getMultiFactorResolver.js +5 -8
  36. package/dist/module/getMultiFactorResolver.js.map +1 -0
  37. package/{lib/providers/FacebookAuthProvider.js → dist/module/index.js} +11 -18
  38. package/dist/module/index.js.map +1 -0
  39. package/dist/module/modular.js +779 -0
  40. package/dist/module/modular.js.map +1 -0
  41. package/{lib → dist/module}/multiFactor.js +16 -14
  42. package/dist/module/multiFactor.js.map +1 -0
  43. package/dist/module/namespaced.js +522 -0
  44. package/dist/module/namespaced.js.map +1 -0
  45. package/dist/module/package.json +1 -0
  46. package/dist/module/password-policy/PasswordPolicyImpl.js +103 -0
  47. package/dist/module/password-policy/PasswordPolicyImpl.js.map +1 -0
  48. package/{lib → dist/module}/password-policy/PasswordPolicyMixin.js +14 -16
  49. package/dist/module/password-policy/PasswordPolicyMixin.js.map +1 -0
  50. package/{lib → dist/module}/password-policy/passwordPolicyApi.js +18 -12
  51. package/dist/module/password-policy/passwordPolicyApi.js.map +1 -0
  52. package/{lib → dist/module}/providers/AppleAuthProvider.js +14 -7
  53. package/dist/module/providers/AppleAuthProvider.js.map +1 -0
  54. package/{lib → dist/module}/providers/EmailAuthProvider.js +10 -25
  55. package/dist/module/providers/EmailAuthProvider.js.map +1 -0
  56. package/dist/module/providers/FacebookAuthProvider.js +56 -0
  57. package/dist/module/providers/FacebookAuthProvider.js.map +1 -0
  58. package/dist/module/providers/GithubAuthProvider.js +49 -0
  59. package/dist/module/providers/GithubAuthProvider.js.map +1 -0
  60. package/dist/module/providers/GoogleAuthProvider.js +57 -0
  61. package/dist/module/providers/GoogleAuthProvider.js.map +1 -0
  62. package/dist/module/providers/OAuthProvider.js +116 -0
  63. package/dist/module/providers/OAuthProvider.js.map +1 -0
  64. package/{lib → dist/module}/providers/OIDCAuthProvider.js +15 -7
  65. package/dist/module/providers/OIDCAuthProvider.js.map +1 -0
  66. package/dist/module/providers/PhoneAuthProvider.js +87 -0
  67. package/dist/module/providers/PhoneAuthProvider.js.map +1 -0
  68. package/dist/module/providers/TwitterAuthProvider.js +50 -0
  69. package/dist/module/providers/TwitterAuthProvider.js.map +1 -0
  70. package/dist/module/types/auth.js +43 -0
  71. package/dist/module/types/auth.js.map +1 -0
  72. package/dist/module/types/internal.js +4 -0
  73. package/dist/module/types/internal.js.map +1 -0
  74. package/dist/module/types/namespaced.js +62 -0
  75. package/dist/module/types/namespaced.js.map +1 -0
  76. package/dist/module/version.js +5 -0
  77. package/dist/module/version.js.map +1 -0
  78. package/dist/module/web/RNFBAuthModule.android.js +5 -0
  79. package/dist/module/web/RNFBAuthModule.android.js.map +1 -0
  80. package/dist/module/web/RNFBAuthModule.ios.js +5 -0
  81. package/dist/module/web/RNFBAuthModule.ios.js.map +1 -0
  82. package/{lib → dist/module}/web/RNFBAuthModule.js +104 -321
  83. package/dist/module/web/RNFBAuthModule.js.map +1 -0
  84. package/dist/typescript/lib/ActionCodeURL.d.ts +41 -0
  85. package/dist/typescript/lib/ActionCodeURL.d.ts.map +1 -0
  86. package/dist/typescript/lib/ConfirmationResult.d.ts +10 -0
  87. package/dist/typescript/lib/ConfirmationResult.d.ts.map +1 -0
  88. package/dist/typescript/lib/MultiFactorResolver.d.ts +24 -0
  89. package/dist/typescript/lib/MultiFactorResolver.d.ts.map +1 -0
  90. package/dist/typescript/lib/PhoneAuthListener.d.ts +34 -0
  91. package/dist/typescript/lib/PhoneAuthListener.d.ts.map +1 -0
  92. package/dist/typescript/lib/PhoneAuthState.d.ts +7 -0
  93. package/dist/typescript/lib/PhoneAuthState.d.ts.map +1 -0
  94. package/dist/typescript/lib/PhoneMultiFactorGenerator.d.ts +7 -0
  95. package/dist/typescript/lib/PhoneMultiFactorGenerator.d.ts.map +1 -0
  96. package/dist/typescript/lib/Settings.d.ts +13 -0
  97. package/dist/typescript/lib/Settings.d.ts.map +1 -0
  98. package/dist/typescript/lib/TotpMultiFactorGenerator.d.ts +11 -0
  99. package/dist/typescript/lib/TotpMultiFactorGenerator.d.ts.map +1 -0
  100. package/dist/typescript/lib/TotpSecret.d.ts +33 -0
  101. package/dist/typescript/lib/TotpSecret.d.ts.map +1 -0
  102. package/dist/typescript/lib/User.d.ts +51 -0
  103. package/dist/typescript/lib/User.d.ts.map +1 -0
  104. package/dist/typescript/lib/constants.d.ts +35 -0
  105. package/dist/typescript/lib/constants.d.ts.map +1 -0
  106. package/dist/typescript/lib/credentials/AuthCredential.d.ts +12 -0
  107. package/dist/typescript/lib/credentials/AuthCredential.d.ts.map +1 -0
  108. package/dist/typescript/lib/credentials/EmailAuthCredential.d.ts +8 -0
  109. package/dist/typescript/lib/credentials/EmailAuthCredential.d.ts.map +1 -0
  110. package/dist/typescript/lib/credentials/OAuthCredential.d.ts +22 -0
  111. package/dist/typescript/lib/credentials/OAuthCredential.d.ts.map +1 -0
  112. package/dist/typescript/lib/credentials/PhoneAuthCredential.d.ts +8 -0
  113. package/dist/typescript/lib/credentials/PhoneAuthCredential.d.ts.map +1 -0
  114. package/dist/typescript/lib/credentials/index.d.ts +5 -0
  115. package/dist/typescript/lib/credentials/index.d.ts.map +1 -0
  116. package/dist/typescript/lib/getMultiFactorResolver.d.ts +19 -0
  117. package/dist/typescript/lib/getMultiFactorResolver.d.ts.map +1 -0
  118. package/dist/typescript/lib/index.d.ts +8 -0
  119. package/dist/typescript/lib/index.d.ts.map +1 -0
  120. package/dist/typescript/lib/modular.d.ts +360 -0
  121. package/dist/typescript/lib/modular.d.ts.map +1 -0
  122. package/dist/typescript/lib/multiFactor.d.ts +26 -0
  123. package/dist/typescript/lib/multiFactor.d.ts.map +1 -0
  124. package/dist/typescript/lib/namespaced.d.ts +12 -0
  125. package/dist/typescript/lib/namespaced.d.ts.map +1 -0
  126. package/dist/typescript/lib/password-policy/PasswordPolicyImpl.d.ts +19 -0
  127. package/dist/typescript/lib/password-policy/PasswordPolicyImpl.d.ts.map +1 -0
  128. package/dist/typescript/lib/password-policy/PasswordPolicyMixin.d.ts +11 -0
  129. package/dist/typescript/lib/password-policy/PasswordPolicyMixin.d.ts.map +1 -0
  130. package/dist/typescript/lib/password-policy/passwordPolicyApi.d.ts +10 -0
  131. package/dist/typescript/lib/password-policy/passwordPolicyApi.d.ts.map +1 -0
  132. package/dist/typescript/lib/providers/AppleAuthProvider.d.ts +16 -0
  133. package/dist/typescript/lib/providers/AppleAuthProvider.d.ts.map +1 -0
  134. package/dist/typescript/lib/providers/EmailAuthProvider.d.ts +11 -0
  135. package/dist/typescript/lib/providers/EmailAuthProvider.d.ts.map +1 -0
  136. package/dist/typescript/lib/providers/FacebookAuthProvider.d.ts +19 -0
  137. package/dist/typescript/lib/providers/FacebookAuthProvider.d.ts.map +1 -0
  138. package/dist/typescript/lib/providers/GithubAuthProvider.d.ts +15 -0
  139. package/dist/typescript/lib/providers/GithubAuthProvider.d.ts.map +1 -0
  140. package/dist/typescript/lib/providers/GoogleAuthProvider.d.ts +21 -0
  141. package/dist/typescript/lib/providers/GoogleAuthProvider.d.ts.map +1 -0
  142. package/dist/typescript/lib/providers/OAuthProvider.d.ts +33 -0
  143. package/dist/typescript/lib/providers/OAuthProvider.d.ts.map +1 -0
  144. package/dist/typescript/lib/providers/OIDCAuthProvider.d.ts +16 -0
  145. package/dist/typescript/lib/providers/OIDCAuthProvider.d.ts.map +1 -0
  146. package/dist/typescript/lib/providers/PhoneAuthProvider.d.ts +16 -0
  147. package/dist/typescript/lib/providers/PhoneAuthProvider.d.ts.map +1 -0
  148. package/dist/typescript/lib/providers/TwitterAuthProvider.d.ts +15 -0
  149. package/dist/typescript/lib/providers/TwitterAuthProvider.d.ts.map +1 -0
  150. package/dist/typescript/lib/types/auth.d.ts +305 -0
  151. package/dist/typescript/lib/types/auth.d.ts.map +1 -0
  152. package/dist/typescript/lib/types/internal.d.ts +292 -0
  153. package/dist/typescript/lib/types/internal.d.ts.map +1 -0
  154. package/dist/typescript/lib/types/namespaced.d.ts +2185 -0
  155. package/dist/typescript/lib/types/namespaced.d.ts.map +1 -0
  156. package/dist/typescript/lib/version.d.ts +2 -0
  157. package/dist/typescript/lib/version.d.ts.map +1 -0
  158. package/dist/typescript/lib/web/RNFBAuthModule.android.d.ts +3 -0
  159. package/dist/typescript/lib/web/RNFBAuthModule.android.d.ts.map +1 -0
  160. package/dist/typescript/lib/web/RNFBAuthModule.d.ts +406 -0
  161. package/dist/typescript/lib/web/RNFBAuthModule.d.ts.map +1 -0
  162. package/dist/typescript/lib/web/RNFBAuthModule.ios.d.ts +3 -0
  163. package/dist/typescript/lib/web/RNFBAuthModule.ios.d.ts.map +1 -0
  164. package/dist/typescript/package.json +1 -0
  165. package/ios/RNFBAuth/RNFBAuthModule.m +4 -2
  166. package/lib/ActionCodeURL.ts +174 -0
  167. package/lib/ConfirmationResult.ts +42 -0
  168. package/lib/MultiFactorResolver.ts +51 -0
  169. package/lib/PhoneAuthListener.ts +312 -0
  170. package/lib/PhoneAuthState.ts +22 -0
  171. package/lib/{PhoneMultiFactorGenerator.js → PhoneMultiFactorGenerator.ts} +8 -2
  172. package/lib/Settings.ts +59 -0
  173. package/lib/TotpMultiFactorGenerator.ts +78 -0
  174. package/lib/TotpSecret.ts +71 -0
  175. package/lib/{User.js → User.ts} +127 -83
  176. package/lib/constants.ts +55 -0
  177. package/lib/credentials/AuthCredential.ts +55 -0
  178. package/lib/credentials/EmailAuthCredential.ts +70 -0
  179. package/lib/credentials/OAuthCredential.ts +113 -0
  180. package/lib/credentials/PhoneAuthCredential.ts +66 -0
  181. package/lib/{providers/GithubAuthProvider.js → credentials/index.ts} +4 -19
  182. package/lib/getMultiFactorResolver.ts +40 -0
  183. package/lib/{providers/TwitterAuthProvider.js → index.ts} +14 -19
  184. package/lib/modular.ts +1158 -0
  185. package/lib/multiFactor.ts +83 -0
  186. package/lib/namespaced.ts +846 -0
  187. package/lib/password-policy/{PasswordPolicyImpl.js → PasswordPolicyImpl.ts} +37 -19
  188. package/lib/password-policy/PasswordPolicyMixin.ts +83 -0
  189. package/lib/password-policy/passwordPolicyApi.ts +60 -0
  190. package/lib/providers/AppleAuthProvider.ts +44 -0
  191. package/lib/providers/EmailAuthProvider.ts +42 -0
  192. package/lib/providers/FacebookAuthProvider.ts +58 -0
  193. package/lib/providers/GithubAuthProvider.ts +51 -0
  194. package/lib/providers/GoogleAuthProvider.ts +60 -0
  195. package/lib/providers/OAuthProvider.ts +150 -0
  196. package/lib/providers/OIDCAuthProvider.ts +49 -0
  197. package/lib/providers/PhoneAuthProvider.ts +161 -0
  198. package/lib/providers/TwitterAuthProvider.ts +52 -0
  199. package/lib/types/auth.ts +393 -0
  200. package/lib/types/internal.ts +474 -0
  201. package/lib/{index.d.ts → types/namespaced.ts} +52 -41
  202. package/lib/version.ts +2 -0
  203. package/lib/web/RNFBAuthModule.ts +1359 -0
  204. package/package.json +41 -9
  205. package/plugin/tsconfig.tsbuildinfo +1 -1
  206. package/tsconfig.json +26 -0
  207. package/tsdoc.json +22 -0
  208. package/typedoc.json +9 -2
  209. package/lib/index.js +0 -572
  210. package/lib/modular/index.d.ts +0 -801
  211. package/lib/modular/index.js +0 -651
  212. package/lib/providers/OAuthProvider.js +0 -70
  213. package/lib/providers/PhoneAuthProvider.js +0 -52
  214. package/lib/version.js +0 -2
  215. /package/lib/web/{RNFBAuthModule.android.js → RNFBAuthModule.android.ts} +0 -0
  216. /package/lib/web/{RNFBAuthModule.ios.js → RNFBAuthModule.ios.ts} +0 -0
@@ -15,6 +15,13 @@
15
15
  *
16
16
  */
17
17
 
18
+ import type {
19
+ PasswordPolicyCustomStrengthOptionsInternal,
20
+ PasswordPolicyInternal,
21
+ PasswordPolicyResponseInternal,
22
+ PasswordValidationStatusInternal,
23
+ } from '../types/internal';
24
+
18
25
  // Minimum min password length enforced by the backend, even if no minimum length is set.
19
26
  const MINIMUM_MIN_PASSWORD_LENGTH = 6;
20
27
 
@@ -23,14 +30,20 @@ const MINIMUM_MIN_PASSWORD_LENGTH = 6;
23
30
  *
24
31
  * @internal
25
32
  */
26
- export class PasswordPolicyImpl {
27
- constructor(response) {
33
+ export class PasswordPolicyImpl implements PasswordPolicyInternal {
34
+ customStrengthOptions: PasswordPolicyCustomStrengthOptionsInternal;
35
+ allowedNonAlphanumericCharacters: string;
36
+ enforcementState: string;
37
+ forceUpgradeOnSignin: boolean;
38
+ schemaVersion: number;
39
+
40
+ constructor(response: PasswordPolicyResponseInternal) {
28
41
  // Only include custom strength options defined in the response.
29
- const responseOptions = response.customStrengthOptions;
42
+ const responseOptions = response.customStrengthOptions ?? {};
30
43
  this.customStrengthOptions = {};
31
44
  this.customStrengthOptions.minPasswordLength =
32
45
  responseOptions.minPasswordLength ?? MINIMUM_MIN_PASSWORD_LENGTH;
33
- if (responseOptions.maxPasswordLength) {
46
+ if (responseOptions.maxPasswordLength !== undefined) {
34
47
  this.customStrengthOptions.maxPasswordLength = responseOptions.maxPasswordLength;
35
48
  }
36
49
  if (responseOptions.containsLowercaseCharacter !== undefined) {
@@ -53,7 +66,7 @@ export class PasswordPolicyImpl {
53
66
  this.enforcementState =
54
67
  response.enforcementState === 'ENFORCEMENT_STATE_UNSPECIFIED'
55
68
  ? 'OFF'
56
- : response.enforcementState;
69
+ : (response.enforcementState ?? 'OFF');
57
70
 
58
71
  // Use an empty string if no non-alphanumeric characters are specified in the response.
59
72
  this.allowedNonAlphanumericCharacters =
@@ -63,8 +76,8 @@ export class PasswordPolicyImpl {
63
76
  this.schemaVersion = response.schemaVersion;
64
77
  }
65
78
 
66
- validatePassword(password) {
67
- const status = {
79
+ validatePassword(password: string): PasswordValidationStatusInternal {
80
+ const status: PasswordValidationStatusInternal = {
68
81
  isValid: true,
69
82
  passwordPolicy: this,
70
83
  };
@@ -82,18 +95,24 @@ export class PasswordPolicyImpl {
82
95
  return status;
83
96
  }
84
97
 
85
- validatePasswordLengthOptions(password, status) {
98
+ private validatePasswordLengthOptions(
99
+ password: string,
100
+ status: PasswordValidationStatusInternal,
101
+ ): void {
86
102
  const minPasswordLength = this.customStrengthOptions.minPasswordLength;
87
103
  const maxPasswordLength = this.customStrengthOptions.maxPasswordLength;
88
- if (minPasswordLength) {
104
+ if (minPasswordLength !== undefined) {
89
105
  status.meetsMinPasswordLength = password.length >= minPasswordLength;
90
106
  }
91
- if (maxPasswordLength) {
107
+ if (maxPasswordLength !== undefined) {
92
108
  status.meetsMaxPasswordLength = password.length <= maxPasswordLength;
93
109
  }
94
110
  }
95
111
 
96
- validatePasswordCharacterOptions(password, status) {
112
+ private validatePasswordCharacterOptions(
113
+ password: string,
114
+ status: PasswordValidationStatusInternal,
115
+ ): void {
97
116
  this.updatePasswordCharacterOptionsStatuses(status, false, false, false, false);
98
117
 
99
118
  for (let i = 0; i < password.length; i++) {
@@ -108,13 +127,13 @@ export class PasswordPolicyImpl {
108
127
  }
109
128
  }
110
129
 
111
- updatePasswordCharacterOptionsStatuses(
112
- status,
113
- containsLowercaseCharacter,
114
- containsUppercaseCharacter,
115
- containsNumericCharacter,
116
- containsNonAlphanumericCharacter,
117
- ) {
130
+ private updatePasswordCharacterOptionsStatuses(
131
+ status: PasswordValidationStatusInternal,
132
+ containsLowercaseCharacter: boolean,
133
+ containsUppercaseCharacter: boolean,
134
+ containsNumericCharacter: boolean,
135
+ containsNonAlphanumericCharacter: boolean,
136
+ ): void {
118
137
  if (this.customStrengthOptions.containsLowercaseLetter) {
119
138
  status.containsLowercaseLetter ||= containsLowercaseCharacter;
120
139
  }
@@ -129,4 +148,3 @@ export class PasswordPolicyImpl {
129
148
  }
130
149
  }
131
150
  }
132
- export default PasswordPolicyImpl;
@@ -0,0 +1,83 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { fetchPasswordPolicy } from './passwordPolicyApi';
19
+ import { PasswordPolicyImpl } from './PasswordPolicyImpl';
20
+ import type {
21
+ PasswordPolicyHostInternal,
22
+ PasswordPolicyInternal,
23
+ PasswordPolicyMixinInternal,
24
+ PasswordValidationStatusInternal,
25
+ } from '../types/internal';
26
+
27
+ const EXPECTED_PASSWORD_POLICY_SCHEMA_VERSION = 1;
28
+
29
+ type PasswordPolicyMixinTarget = PasswordPolicyHostInternal & PasswordPolicyMixinInternal;
30
+ type PasswordPolicyMixinShape = PasswordPolicyMixinInternal & ThisType<PasswordPolicyMixinTarget>;
31
+
32
+ /**
33
+ * Password policy mixin - provides password policy caching and validation.
34
+ * Expects the target object to have: _tenantId, _projectPasswordPolicy,
35
+ * _tenantPasswordPolicies, and app.options.apiKey
36
+ */
37
+ export const PasswordPolicyMixin: PasswordPolicyMixinShape = {
38
+ _getPasswordPolicyInternal(): PasswordPolicyInternal | null {
39
+ if (this._tenantId === null) {
40
+ return this._projectPasswordPolicy;
41
+ }
42
+ return this._tenantPasswordPolicies[this._tenantId] ?? null;
43
+ },
44
+
45
+ async _updatePasswordPolicy(): Promise<void> {
46
+ const response = await fetchPasswordPolicy(this);
47
+ const passwordPolicy = new PasswordPolicyImpl(response);
48
+ if (this._tenantId === null) {
49
+ this._projectPasswordPolicy = passwordPolicy;
50
+ } else {
51
+ this._tenantPasswordPolicies[this._tenantId] = passwordPolicy;
52
+ }
53
+ },
54
+
55
+ async _recachePasswordPolicy(): Promise<void> {
56
+ if (this._getPasswordPolicyInternal()) {
57
+ await this._updatePasswordPolicy();
58
+ }
59
+ },
60
+
61
+ async validatePassword(password: string): Promise<PasswordValidationStatusInternal> {
62
+ let passwordPolicy = this._getPasswordPolicyInternal();
63
+
64
+ if (!passwordPolicy) {
65
+ await this._updatePasswordPolicy();
66
+ passwordPolicy = this._getPasswordPolicyInternal();
67
+ }
68
+
69
+ if (!passwordPolicy) {
70
+ throw new Error(
71
+ 'firebase.auth().validatePassword(*) Failed to load password policy for validation.',
72
+ );
73
+ }
74
+
75
+ if (passwordPolicy.schemaVersion !== EXPECTED_PASSWORD_POLICY_SCHEMA_VERSION) {
76
+ throw new Error(
77
+ 'auth/unsupported-password-policy-schema-version: The password policy received from the backend uses a schema version that is not supported by this version of the SDK.',
78
+ );
79
+ }
80
+
81
+ return passwordPolicy.validatePassword(password);
82
+ },
83
+ };
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import type { PasswordPolicyHostInternal, PasswordPolicyResponseInternal } from '../types/internal';
19
+
20
+ function getErrorMessage(error: unknown): string {
21
+ if (error instanceof Error) {
22
+ return error.message;
23
+ }
24
+
25
+ return String(error);
26
+ }
27
+
28
+ /**
29
+ * Performs an API request to Firebase Console to get password policy json.
30
+ *
31
+ * @param {Object} auth - The authentication instance
32
+ * @returns {Promise<Response>} A promise that resolves to the API response.
33
+ * @throws {Error} Throws an error if the request fails or encounters an issue.
34
+ */
35
+ export async function fetchPasswordPolicy(
36
+ auth: PasswordPolicyHostInternal,
37
+ ): Promise<PasswordPolicyResponseInternal> {
38
+ let response: Response;
39
+
40
+ try {
41
+ // Identity toolkit API endpoint for password policy. Ensure this is enabled on Google cloud.
42
+ const baseURL = 'https://identitytoolkit.googleapis.com/v2/passwordPolicy?key=';
43
+ const apiKey = auth.app.options.apiKey;
44
+
45
+ response = await fetch(`${baseURL}${apiKey}`);
46
+ } catch (error) {
47
+ throw new Error(
48
+ `firebase.auth().validatePassword(*) Failed to fetch password policy: ${getErrorMessage(error)}`,
49
+ );
50
+ }
51
+
52
+ if (!response.ok) {
53
+ const errorDetails = await response.text();
54
+ throw new Error(
55
+ `firebase.auth().validatePassword(*) failed to fetch password policy from Firebase Console: ${response.statusText}. Details: ${errorDetails}`,
56
+ );
57
+ }
58
+
59
+ return (await response.json()) as PasswordPolicyResponseInternal;
60
+ }
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { AuthCredential } from '../credentials';
19
+ import type { AuthCredential as AuthCredentialType } from '../types/auth';
20
+
21
+ const providerId = 'apple.com' as const;
22
+
23
+ /**
24
+ * @deprecated Use {@link OAuthProvider} with provider ID `apple.com` instead.
25
+ *
26
+ * @example
27
+ * ```js
28
+ * const provider = new OAuthProvider('apple.com');
29
+ * const credential = provider.credential({ idToken, rawNonce });
30
+ * ```
31
+ */
32
+ export default class AppleAuthProvider {
33
+ constructor() {
34
+ throw new Error('`new AppleAuthProvider()` is not supported on the native Firebase SDKs.');
35
+ }
36
+
37
+ static get PROVIDER_ID() {
38
+ return providerId;
39
+ }
40
+
41
+ static credential(token: string, secret?: string): AuthCredentialType {
42
+ return new AuthCredential(providerId, providerId, token, secret ?? '');
43
+ }
44
+ }
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { createEmailAuthCredential } from '../credentials';
19
+ import type { EmailAuthCredential } from '../types/auth';
20
+
21
+ const linkProviderId = 'emailLink' as const;
22
+ const passwordProviderId = 'password' as const;
23
+
24
+ export default class EmailAuthProvider {
25
+ static readonly EMAIL_LINK_SIGN_IN_METHOD: 'emailLink' = linkProviderId;
26
+ static readonly EMAIL_PASSWORD_SIGN_IN_METHOD: 'password' = passwordProviderId;
27
+ static readonly PROVIDER_ID: 'password' = passwordProviderId;
28
+
29
+ readonly providerId = passwordProviderId;
30
+
31
+ constructor() {
32
+ throw new Error('`new EmailAuthProvider()` is not supported on the native Firebase SDKs.');
33
+ }
34
+
35
+ static credential(email: string, password: string): EmailAuthCredential {
36
+ return createEmailAuthCredential(email, password, passwordProviderId);
37
+ }
38
+
39
+ static credentialWithLink(email: string, emailLink: string): EmailAuthCredential {
40
+ return createEmailAuthCredential(email, emailLink, linkProviderId);
41
+ }
42
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { OAuthCredential } from '../credentials';
19
+ import type { AuthError, UserCredential } from '../types/auth';
20
+
21
+ // Keep the SDK helper signature name while mapping to RNFB's native auth error type.
22
+ type FirebaseError = AuthError;
23
+
24
+ const providerId = 'facebook.com' as const;
25
+
26
+ export default class FacebookAuthProvider {
27
+ static readonly FACEBOOK_SIGN_IN_METHOD: 'facebook.com' = providerId;
28
+ static readonly PROVIDER_ID: 'facebook.com' = providerId;
29
+
30
+ constructor() {
31
+ throw new Error('`new FacebookAuthProvider()` is not supported on the native Firebase SDKs.');
32
+ }
33
+
34
+ /**
35
+ * @remarks Optional `secret` for Facebook limited-login nonce behaviour (matches firebase-js-sdk).
36
+ */
37
+ static credential(token: string): OAuthCredential;
38
+ static credential(token: string, secret: string): OAuthCredential;
39
+ static credential(token: string, secret?: string): OAuthCredential {
40
+ const nonce = secret ?? '';
41
+ return new OAuthCredential(providerId, {
42
+ accessToken: token,
43
+ rawNonce: nonce || undefined,
44
+ bridgeToken: token,
45
+ bridgeSecret: nonce,
46
+ });
47
+ }
48
+
49
+ /** @remarks Always returns `null` on React Native Firebase. */
50
+ static credentialFromResult(_userCredential: UserCredential): OAuthCredential | null {
51
+ return null;
52
+ }
53
+
54
+ /** @remarks Always returns `null` on React Native Firebase. */
55
+ static credentialFromError(_error: FirebaseError): OAuthCredential | null {
56
+ return null;
57
+ }
58
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { OAuthCredential } from '../credentials';
19
+ import type { AuthError, UserCredential } from '../types/auth';
20
+
21
+ // Keep the SDK helper signature name while mapping to RNFB's native auth error type.
22
+ type FirebaseError = AuthError;
23
+
24
+ const providerId = 'github.com' as const;
25
+
26
+ export default class GithubAuthProvider {
27
+ static readonly GITHUB_SIGN_IN_METHOD: 'github.com' = providerId;
28
+ static readonly PROVIDER_ID: 'github.com' = providerId;
29
+
30
+ constructor() {
31
+ throw new Error('`new GithubAuthProvider()` is not supported on the native Firebase SDKs.');
32
+ }
33
+
34
+ static credential(token: string): OAuthCredential {
35
+ return new OAuthCredential(providerId, {
36
+ accessToken: token,
37
+ bridgeToken: token,
38
+ bridgeSecret: '',
39
+ });
40
+ }
41
+
42
+ /** @remarks Always returns `null` on React Native Firebase. */
43
+ static credentialFromResult(_userCredential: UserCredential): OAuthCredential | null {
44
+ return null;
45
+ }
46
+
47
+ /** @remarks Always returns `null` on React Native Firebase. */
48
+ static credentialFromError(_error: FirebaseError): OAuthCredential | null {
49
+ return null;
50
+ }
51
+ }
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { OAuthCredential } from '../credentials';
19
+ import type { AuthError, UserCredential } from '../types/auth';
20
+
21
+ // Keep the SDK helper signature name while mapping to RNFB's native auth error type.
22
+ type FirebaseError = AuthError;
23
+
24
+ const providerId = 'google.com' as const;
25
+
26
+ export default class GoogleAuthProvider {
27
+ static readonly GOOGLE_SIGN_IN_METHOD: 'google.com' = providerId;
28
+ static readonly PROVIDER_ID: 'google.com' = providerId;
29
+
30
+ constructor() {
31
+ throw new Error('`new GoogleAuthProvider()` is not supported on the native Firebase SDKs.');
32
+ }
33
+
34
+ static credential(idToken?: string | null, accessToken?: string | null): OAuthCredential {
35
+ if (idToken == null && accessToken == null) {
36
+ throw new Error('At least one of ID token and access token must be non-null');
37
+ }
38
+
39
+ return new OAuthCredential(providerId, {
40
+ idToken: idToken ?? undefined,
41
+ accessToken: accessToken ?? undefined,
42
+ });
43
+ }
44
+
45
+ /**
46
+ * @remarks Always returns `null` on React Native Firebase. Credentials are not extractable from
47
+ * native provider sign-in results.
48
+ */
49
+ static credentialFromResult(_userCredential: UserCredential): OAuthCredential | null {
50
+ return null;
51
+ }
52
+
53
+ /**
54
+ * @remarks Always returns `null` on React Native Firebase. Credentials are not extractable from
55
+ * native provider errors.
56
+ */
57
+ static credentialFromError(_error: FirebaseError): OAuthCredential | null {
58
+ return null;
59
+ }
60
+ }
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ import { OAuthCredential } from '../credentials';
19
+ import type {
20
+ AuthCredential,
21
+ AuthError,
22
+ CustomParameters,
23
+ OAuthCredentialOptions,
24
+ UserCredential,
25
+ } from '../types/auth';
26
+
27
+ type OAuthCredentialJSON = OAuthCredentialOptions & {
28
+ providerId?: string;
29
+ nonce?: string;
30
+ };
31
+
32
+ type ParsedOAuthCredentialJSON = OAuthCredentialOptions & {
33
+ providerId: string;
34
+ nonce?: string;
35
+ };
36
+
37
+ function parseOAuthCredentialJSON(json: object | string): ParsedOAuthCredentialJSON {
38
+ let parsed: object;
39
+
40
+ if (typeof json === 'string') {
41
+ try {
42
+ parsed = JSON.parse(json);
43
+ } catch {
44
+ throw new Error(
45
+ "firebase.auth.OAuthProvider.credentialFromJSON(*) expected 'json' to be a valid JSON string.",
46
+ );
47
+ }
48
+ } else {
49
+ if (json === null || Array.isArray(json)) {
50
+ throw new Error(
51
+ "firebase.auth.OAuthProvider.credentialFromJSON(*) expected 'json' to be an object or string.",
52
+ );
53
+ }
54
+ parsed = json;
55
+ }
56
+
57
+ const credential = parsed as OAuthCredentialJSON;
58
+ if (typeof credential.providerId !== 'string') {
59
+ throw new Error(
60
+ "firebase.auth.OAuthProvider.credentialFromJSON(*) expected 'providerId' to be a string value.",
61
+ );
62
+ }
63
+
64
+ return credential as ParsedOAuthCredentialJSON;
65
+ }
66
+
67
+ // Keep the SDK helper signature name while mapping to RNFB's native auth error type.
68
+ type FirebaseError = AuthError;
69
+
70
+ export default class OAuthProvider {
71
+ /** @internal */
72
+ private providerId: string;
73
+ /** @internal */
74
+ private customParameters: CustomParameters = {};
75
+ /** @internal */
76
+ private scopes: string[] = [];
77
+
78
+ constructor(providerId: string) {
79
+ this.providerId = providerId;
80
+ }
81
+
82
+ /** @internal */
83
+ static credential(idToken: string, accessToken?: string): AuthCredential {
84
+ return new OAuthProvider('oauth').credential({
85
+ idToken,
86
+ accessToken,
87
+ });
88
+ }
89
+
90
+ static credentialFromJSON(json: object | string): OAuthCredential {
91
+ const credential = parseOAuthCredentialJSON(json);
92
+
93
+ return new OAuthProvider(credential.providerId).credential({
94
+ idToken: credential.idToken,
95
+ accessToken: credential.accessToken,
96
+ rawNonce: credential.rawNonce ?? credential.nonce,
97
+ });
98
+ }
99
+
100
+ /** @remarks Always returns `null` on React Native Firebase. */
101
+ static credentialFromResult(_userCredential: UserCredential): OAuthCredential | null {
102
+ return null;
103
+ }
104
+
105
+ /** @remarks Always returns `null` on React Native Firebase. */
106
+ static credentialFromError(_error: FirebaseError): OAuthCredential | null {
107
+ return null;
108
+ }
109
+
110
+ credential(params: OAuthCredentialOptions): OAuthCredential {
111
+ return new OAuthCredential(this.providerId, {
112
+ idToken: params.idToken,
113
+ accessToken: params.accessToken,
114
+ rawNonce: params.rawNonce,
115
+ });
116
+ }
117
+
118
+ get PROVIDER_ID() {
119
+ return this.providerId;
120
+ }
121
+
122
+ setCustomParameters(customOAuthParameters: CustomParameters): OAuthProvider {
123
+ this.customParameters = customOAuthParameters;
124
+ return this;
125
+ }
126
+
127
+ getCustomParameters(): CustomParameters {
128
+ return this.customParameters;
129
+ }
130
+
131
+ addScope(scope: string): OAuthProvider {
132
+ if (!this.scopes.includes(scope)) {
133
+ this.scopes.push(scope);
134
+ }
135
+ return this;
136
+ }
137
+
138
+ getScopes(): string[] {
139
+ return [...this.scopes];
140
+ }
141
+
142
+ /** @internal */
143
+ toObject(): { providerId: string; scopes: string[]; customParameters: CustomParameters } {
144
+ return {
145
+ providerId: this.providerId,
146
+ scopes: this.scopes,
147
+ customParameters: this.customParameters,
148
+ };
149
+ }
150
+ }