UNPKG

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