app-check-api.d.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*! firebase-admin v12.1.1 */
  2. /*!
  3. * @license
  4. * Copyright 2021 Google Inc.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * Interface representing an App Check token.
  20. */
  21. export interface AppCheckToken {
  22. /**
  23. * The Firebase App Check token.
  24. */
  25. token: string;
  26. /**
  27. * The time-to-live duration of the token in milliseconds.
  28. */
  29. ttlMillis: number;
  30. }
  31. /**
  32. * Interface representing App Check token options.
  33. */
  34. export interface AppCheckTokenOptions {
  35. /**
  36. * The length of time, in milliseconds, for which the App Check token will
  37. * be valid. This value must be between 30 minutes and 7 days, inclusive.
  38. */
  39. ttlMillis?: number;
  40. }
  41. /**
  42. * Interface representing options for the {@link AppCheck.verifyToken} method.
  43. */
  44. export interface VerifyAppCheckTokenOptions {
  45. /**
  46. * To use the replay protection feature, set this to `true`. The {@link AppCheck.verifyToken}
  47. * method will mark the token as consumed after verifying it.
  48. *
  49. * Tokens that are found to be already consumed will be marked as such in the response.
  50. *
  51. * Tokens are only considered to be consumed if it is sent to App Check backend by calling the
  52. * {@link AppCheck.verifyToken} method with this field set to `true`; other uses of the token
  53. * do not consume it.
  54. *
  55. * This replay protection feature requires an additional network call to the App Check backend
  56. * and forces your clients to obtain a fresh attestation from your chosen attestation providers.
  57. * This can therefore negatively impact performance and can potentially deplete your attestation
  58. * providers' quotas faster. We recommend that you use this feature only for protecting
  59. * low volume, security critical, or expensive operations.
  60. */
  61. consume?: boolean;
  62. }
  63. /**
  64. * Interface representing a decoded Firebase App Check token, returned from the
  65. * {@link AppCheck.verifyToken} method.
  66. */
  67. export interface DecodedAppCheckToken {
  68. /**
  69. * The issuer identifier for the issuer of the response.
  70. * This value is a URL with the format
  71. * `https://firebaseappcheck.googleapis.com/<PROJECT_NUMBER>`, where `<PROJECT_NUMBER>` is the
  72. * same project number specified in the {@link DecodedAppCheckToken.aud | aud} property.
  73. */
  74. iss: string;
  75. /**
  76. * The Firebase App ID corresponding to the app the token belonged to.
  77. * As a convenience, this value is copied over to the {@link DecodedAppCheckToken.app_id | app_id} property.
  78. */
  79. sub: string;
  80. /**
  81. * The audience for which this token is intended.
  82. * This value is a JSON array of two strings, the first is the project number of your
  83. * Firebase project, and the second is the project ID of the same project.
  84. */
  85. aud: string[];
  86. /**
  87. * The App Check token's expiration time, in seconds since the Unix epoch. That is, the
  88. * time at which this App Check token expires and should no longer be considered valid.
  89. */
  90. exp: number;
  91. /**
  92. * The App Check token's issued-at time, in seconds since the Unix epoch. That is, the
  93. * time at which this App Check token was issued and should start to be considered
  94. * valid.
  95. */
  96. iat: number;
  97. /**
  98. * The App ID corresponding to the App the App Check token belonged to.
  99. * This value is not actually one of the JWT token claims. It is added as a
  100. * convenience, and is set as the value of the {@link DecodedAppCheckToken.sub | sub} property.
  101. */
  102. app_id: string;
  103. [key: string]: any;
  104. }
  105. /**
  106. * Interface representing a verified App Check token response.
  107. */
  108. export interface VerifyAppCheckTokenResponse {
  109. /**
  110. * The App ID corresponding to the App the App Check token belonged to.
  111. */
  112. appId: string;
  113. /**
  114. * The decoded Firebase App Check token.
  115. */
  116. token: DecodedAppCheckToken;
  117. /**
  118. * Indicates weather this token was already consumed.
  119. * If this is the first time {@link AppCheck.verifyToken} method has seen this token,
  120. * this field will contain the value `false`. The given token will then be
  121. * marked as `already_consumed` for all future invocations of this {@link AppCheck.verifyToken}
  122. * method for this token.
  123. *
  124. * When this field is `true`, the caller is attempting to reuse a previously consumed token.
  125. * You should take precautions against such a caller; for example, you can take actions such as
  126. * rejecting the request or ask the caller to pass additional layers of security checks.
  127. */
  128. alreadyConsumed?: boolean;
  129. }