Няма описание
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. * Firebase App Check
  3. *
  4. * @packageDocumentation
  5. */
  6. import { FirebaseApp } from '@firebase/app';
  7. import { PartialObserver } from '@firebase/util';
  8. import { Unsubscribe } from '@firebase/util';
  9. /**
  10. * The Firebase App Check service interface.
  11. *
  12. * @public
  13. */
  14. export declare interface AppCheck {
  15. /**
  16. * The {@link @firebase/app#FirebaseApp} this `AppCheck` instance is associated with.
  17. */
  18. app: FirebaseApp;
  19. }
  20. /**
  21. * @internal
  22. */
  23. export declare type _AppCheckComponentName = 'app-check';
  24. /**
  25. * @internal
  26. */
  27. export declare type _AppCheckInternalComponentName = 'app-check-internal';
  28. /**
  29. * Options for App Check initialization.
  30. * @public
  31. */
  32. export declare interface AppCheckOptions {
  33. /**
  34. * A reCAPTCHA V3 provider, reCAPTCHA Enterprise provider, or custom provider.
  35. */
  36. provider: CustomProvider | ReCaptchaV3Provider | ReCaptchaEnterpriseProvider;
  37. /**
  38. * If set to true, enables automatic background refresh of App Check token.
  39. */
  40. isTokenAutoRefreshEnabled?: boolean;
  41. }
  42. declare interface AppCheckProvider {
  43. /**
  44. * Returns an App Check token.
  45. * @internal
  46. */
  47. getToken: () => Promise<AppCheckTokenInternal>;
  48. /**
  49. * @internal
  50. */
  51. initialize(app: FirebaseApp): void;
  52. }
  53. /**
  54. * The token returned from an App Check provider.
  55. * @public
  56. */
  57. export declare interface AppCheckToken {
  58. readonly token: string;
  59. /**
  60. * The local timestamp after which the token will expire.
  61. */
  62. readonly expireTimeMillis: number;
  63. }
  64. declare interface AppCheckTokenInternal extends AppCheckToken {
  65. issuedAtTimeMillis: number;
  66. }
  67. /**
  68. * A listener that is called whenever the App Check token changes.
  69. * @public
  70. */
  71. export declare type AppCheckTokenListener = (token: AppCheckTokenResult) => void;
  72. /**
  73. * Result returned by `getToken()`.
  74. * @public
  75. */
  76. export declare interface AppCheckTokenResult {
  77. /**
  78. * The token string in JWT format.
  79. */
  80. readonly token: string;
  81. }
  82. /**
  83. * Custom provider class.
  84. * @public
  85. */
  86. export declare class CustomProvider implements AppCheckProvider {
  87. private _customProviderOptions;
  88. private _app?;
  89. constructor(_customProviderOptions: CustomProviderOptions);
  90. /**
  91. * @internal
  92. */
  93. getToken(): Promise<AppCheckTokenInternal>;
  94. /**
  95. * @internal
  96. */
  97. initialize(app: FirebaseApp): void;
  98. /**
  99. * @internal
  100. */
  101. isEqual(otherProvider: unknown): boolean;
  102. }
  103. /**
  104. * Options when creating a {@link CustomProvider}.
  105. * @public
  106. */
  107. export declare interface CustomProviderOptions {
  108. /**
  109. * Function to get an App Check token through a custom provider
  110. * service.
  111. */
  112. getToken: () => Promise<AppCheckToken>;
  113. }
  114. /**
  115. * Get the current App Check token. Attaches to the most recent
  116. * in-flight request if one is present. Returns null if no token
  117. * is present and no token requests are in-flight.
  118. *
  119. * @param appCheckInstance - The App Check service instance.
  120. * @param forceRefresh - If true, will always try to fetch a fresh token.
  121. * If false, will use a cached token if found in storage.
  122. * @public
  123. */
  124. export declare function getToken(appCheckInstance: AppCheck, forceRefresh?: boolean): Promise<AppCheckTokenResult>;
  125. /**
  126. * Activate App Check for the given app. Can be called only once per app.
  127. * @param app - the {@link @firebase/app#FirebaseApp} to activate App Check for
  128. * @param options - App Check initialization options
  129. * @public
  130. */
  131. export declare function initializeAppCheck(app: FirebaseApp | undefined, options: AppCheckOptions): AppCheck;
  132. /**
  133. * Registers a listener to changes in the token state. There can be more
  134. * than one listener registered at the same time for one or more
  135. * App Check instances. The listeners call back on the UI thread whenever
  136. * the current token associated with this App Check instance changes.
  137. *
  138. * @param appCheckInstance - The App Check service instance.
  139. * @param observer - An object with `next`, `error`, and `complete`
  140. * properties. `next` is called with an
  141. * {@link AppCheckTokenResult}
  142. * whenever the token changes. `error` is optional and is called if an
  143. * error is thrown by the listener (the `next` function). `complete`
  144. * is unused, as the token stream is unending.
  145. *
  146. * @returns A function that unsubscribes this listener.
  147. * @public
  148. */
  149. export declare function onTokenChanged(appCheckInstance: AppCheck, observer: PartialObserver<AppCheckTokenResult>): Unsubscribe;
  150. /**
  151. * Registers a listener to changes in the token state. There can be more
  152. * than one listener registered at the same time for one or more
  153. * App Check instances. The listeners call back on the UI thread whenever
  154. * the current token associated with this App Check instance changes.
  155. *
  156. * @param appCheckInstance - The App Check service instance.
  157. * @param onNext - When the token changes, this function is called with aa
  158. * {@link AppCheckTokenResult}.
  159. * @param onError - Optional. Called if there is an error thrown by the
  160. * listener (the `onNext` function).
  161. * @param onCompletion - Currently unused, as the token stream is unending.
  162. * @returns A function that unsubscribes this listener.
  163. * @public
  164. */
  165. export declare function onTokenChanged(appCheckInstance: AppCheck, onNext: (tokenResult: AppCheckTokenResult) => void, onError?: (error: Error) => void, onCompletion?: () => void): Unsubscribe;
  166. export { PartialObserver }
  167. /**
  168. * App Check provider that can obtain a reCAPTCHA Enterprise token and exchange it
  169. * for an App Check token.
  170. *
  171. * @public
  172. */
  173. export declare class ReCaptchaEnterpriseProvider implements AppCheckProvider {
  174. private _siteKey;
  175. private _app?;
  176. private _heartbeatServiceProvider?;
  177. /**
  178. * Throttle requests on certain error codes to prevent too many retries
  179. * in a short time.
  180. */
  181. private _throttleData;
  182. /**
  183. * Create a ReCaptchaEnterpriseProvider instance.
  184. * @param siteKey - reCAPTCHA Enterprise score-based site key.
  185. */
  186. constructor(_siteKey: string);
  187. /**
  188. * Returns an App Check token.
  189. * @internal
  190. */
  191. getToken(): Promise<AppCheckTokenInternal>;
  192. /**
  193. * @internal
  194. */
  195. initialize(app: FirebaseApp): void;
  196. /**
  197. * @internal
  198. */
  199. isEqual(otherProvider: unknown): boolean;
  200. }
  201. /**
  202. * App Check provider that can obtain a reCAPTCHA V3 token and exchange it
  203. * for an App Check token.
  204. *
  205. * @public
  206. */
  207. export declare class ReCaptchaV3Provider implements AppCheckProvider {
  208. private _siteKey;
  209. private _app?;
  210. private _heartbeatServiceProvider?;
  211. /**
  212. * Throttle requests on certain error codes to prevent too many retries
  213. * in a short time.
  214. */
  215. private _throttleData;
  216. /**
  217. * Create a ReCaptchaV3Provider instance.
  218. * @param siteKey - ReCAPTCHA V3 siteKey.
  219. */
  220. constructor(_siteKey: string);
  221. /**
  222. * Returns an App Check token.
  223. * @internal
  224. */
  225. getToken(): Promise<AppCheckTokenInternal>;
  226. /**
  227. * @internal
  228. */
  229. initialize(app: FirebaseApp): void;
  230. /**
  231. * @internal
  232. */
  233. isEqual(otherProvider: unknown): boolean;
  234. }
  235. /**
  236. * Set whether App Check will automatically refresh tokens as needed.
  237. *
  238. * @param appCheckInstance - The App Check service instance.
  239. * @param isTokenAutoRefreshEnabled - If true, the SDK automatically
  240. * refreshes App Check tokens as needed. This overrides any value set
  241. * during `initializeAppCheck()`.
  242. * @public
  243. */
  244. export declare function setTokenAutoRefreshEnabled(appCheckInstance: AppCheck, isTokenAutoRefreshEnabled: boolean): void;
  245. export { Unsubscribe }
  246. export { }