Skip to content

Commit f29bf72

Browse files
Merge pull request DefinitelyTyped#7583 from dotdotcommadot/master
Adds firebase-token-generator
2 parents 4671918 + a1f0448 commit f29bf72

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--module commonjs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="firebase-token-generator.d.ts"/>
2+
import FirebaseTokenGenerator = require('firebase-token-generator');
3+
4+
const tokenGenerator: FirebaseTokenGenerator = new FirebaseTokenGenerator("MY_SECRET");
5+
6+
let token: string = tokenGenerator.createToken({blah: 5, uid: "blah"});
7+
log("Token should not be empty string", (token !== ""));
8+
log("Token should consist of three parts", (token.split(".").length === 3));
9+
10+
token = tokenGenerator.createToken({blah: 5}, {expires : 1234, notBefore : 133234, admin : true, debug : false});
11+
log("Token should take valid options", (token !== ""));
12+
13+
function log(description: string, statement: boolean) : void {
14+
console.log((statement? "SUCCESS" : "FAIL") + " " + description);
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)