|
| 1 | +// Type definitions for firebase-token-generator v2.0.0 |
| 2 | +// Project: https://github.com/firebase/firebase-token-generator-node |
| 3 | +// Definitions by: Hans Van den Keybus <https://github.com/dotdotcommadot> |
| 4 | +// Definitions: https://github.com/borisyankov/DefinitelyTyped |
| 5 | + |
| 6 | +interface TokenOptions { |
| 7 | + expires?: number; |
| 8 | + notBefore?: number; |
| 9 | + admin?: boolean; |
| 10 | + debug?: boolean; |
| 11 | + simulate?: boolean; |
| 12 | + iat?: number; |
| 13 | +} |
| 14 | + |
| 15 | +declare class FirebaseTokenGenerator { |
| 16 | + |
| 17 | + /** |
| 18 | + * Builds a new object that can generate Firebase authentication tokens. |
| 19 | + * @constructor |
| 20 | + * @param { String } secret The secret for the Firebase being used (get yours from the Firebase Admin Console). |
| 21 | + */ |
| 22 | + constructor(secret: string); |
| 23 | + |
| 24 | + /** |
| 25 | + * Creates a token that authenticates a client with arbitrary data "data", and the specified options. |
| 26 | + * |
| 27 | + * @param { any } data JSON data that will be passed to the Firebase Rules API once a client authenticates. Unless the |
| 28 | + * "admin" flag is set, it must contain a "uid" key, and if it does it must be a string of length |
| 29 | + * 256 or less. |
| 30 | + * @param { TokenOptions } options The developer-supplied options for this token. Supported options are: |
| 31 | + * a) "expires" -- A timestamp (as a number of seconds since the epoch) denoting a time after which |
| 32 | + * this token should no longer be valid. |
| 33 | + * b) "notBefore" -- A timestamp (as a number of seconds since the epoch) denoting a time before |
| 34 | + * which this token should be rejected by the server. |
| 35 | + * c) "admin" -- Set to true to bypass all security rules (use this for your trusted servers). |
| 36 | + * d) "debug" -- Set to true to enable debug mode (so you can see the results of Rules API operations) |
| 37 | + * e) "simulate" -- (internal-only for now) Set to true to neuter all API operations (listens / puts |
| 38 | + * will run security rules but not actually write or return data) |
| 39 | + * f) "iat" -- (Number) (internal-only, for testing) Set the issued at time for the generated token |
| 40 | + * @return {String} The authentication token |
| 41 | + */ |
| 42 | + createToken(data: any, options?: TokenOptions): string; |
| 43 | +} |
| 44 | + |
| 45 | +declare module 'firebase-token-generator' { |
| 46 | + export = FirebaseTokenGenerator; |
| 47 | +} |
0 commit comments