UNPKG

2.34 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;
8 notBefore?: number;
9 admin?: boolean;
10 debug?: boolean;
11 simulate?: boolean;
12 iat?: number;
13}
14
15declare 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
45declare module 'firebase-token-generator' {
46 export = FirebaseTokenGenerator;
47}