暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

app-check-public.d.ts 7.0KB

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