mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 09:01:45 +08:00
Adds firebase-token-generator
This commit is contained in:
@@ -0,0 +1 @@
|
||||
--module commonjs
|
||||
15
firebase-token-generator/firebase-token-generator-tests.ts
Normal file
15
firebase-token-generator/firebase-token-generator-tests.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="firebase-token-generator.d.ts"/>
|
||||
import FirebaseTokenGenerator = require('firebase-token-generator');
|
||||
|
||||
const tokenGenerator: FirebaseTokenGenerator = new FirebaseTokenGenerator("MY_SECRET");
|
||||
|
||||
let token: string = tokenGenerator.createToken({blah: 5, uid: "blah"});
|
||||
log("Token should not be empty string", (token !== ""));
|
||||
log("Token should consist of three parts", (token.split(".").length === 3));
|
||||
|
||||
token = tokenGenerator.createToken({blah: 5}, {expires : 1234, notBefore : 133234, admin : true, debug : false});
|
||||
log("Token should take valid options", (token !== ""));
|
||||
|
||||
function log(description: string, statement: boolean) : void {
|
||||
console.log((statement? "SUCCESS" : "FAIL") + " " + description);
|
||||
}
|
||||
47
firebase-token-generator/firebase-token-generator.d.ts
vendored
Normal file
47
firebase-token-generator/firebase-token-generator.d.ts
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
// Type definitions for firebase-token-generator v2.0.0
|
||||
// Project: https://github.com/firebase/firebase-token-generator-node
|
||||
// Definitions by: Hans Van den Keybus <https://github.com/dotdotcommadot>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface TokenOptions {
|
||||
expires?: number;
|
||||
notBefore?: number;
|
||||
admin?: boolean;
|
||||
debug?: boolean;
|
||||
simulate?: boolean;
|
||||
iat?: number;
|
||||
}
|
||||
|
||||
declare class FirebaseTokenGenerator {
|
||||
|
||||
/**
|
||||
* Builds a new object that can generate Firebase authentication tokens.
|
||||
* @constructor
|
||||
* @param { String } secret The secret for the Firebase being used (get yours from the Firebase Admin Console).
|
||||
*/
|
||||
constructor(secret: string);
|
||||
|
||||
/**
|
||||
* Creates a token that authenticates a client with arbitrary data "data", and the specified options.
|
||||
*
|
||||
* @param { any } data JSON data that will be passed to the Firebase Rules API once a client authenticates. Unless the
|
||||
* "admin" flag is set, it must contain a "uid" key, and if it does it must be a string of length
|
||||
* 256 or less.
|
||||
* @param { TokenOptions } options The developer-supplied options for this token. Supported options are:
|
||||
* a) "expires" -- A timestamp (as a number of seconds since the epoch) denoting a time after which
|
||||
* this token should no longer be valid.
|
||||
* b) "notBefore" -- A timestamp (as a number of seconds since the epoch) denoting a time before
|
||||
* which this token should be rejected by the server.
|
||||
* c) "admin" -- Set to true to bypass all security rules (use this for your trusted servers).
|
||||
* d) "debug" -- Set to true to enable debug mode (so you can see the results of Rules API operations)
|
||||
* e) "simulate" -- (internal-only for now) Set to true to neuter all API operations (listens / puts
|
||||
* will run security rules but not actually write or return data)
|
||||
* f) "iat" -- (Number) (internal-only, for testing) Set the issued at time for the generated token
|
||||
* @return {String} The authentication token
|
||||
*/
|
||||
createToken(data: any, options?: TokenOptions): string;
|
||||
}
|
||||
|
||||
declare module 'firebase-token-generator' {
|
||||
export = FirebaseTokenGenerator;
|
||||
}
|
||||
Reference in New Issue
Block a user