UNPKG

2.61 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17interface Claims {
18 [key: string]: {};
19}
20interface DecodedToken {
21 header: object;
22 claims: Claims;
23 data: object;
24 signature: string;
25}
26/**
27 * Decodes a Firebase auth. token into constituent parts.
28 *
29 * Notes:
30 * - May return with invalid / incomplete claims if there's no native base64 decoding support.
31 * - Doesn't check if the token is actually valid.
32 */
33export declare const decode: (token: string) => DecodedToken;
34interface DecodedToken {
35 header: object;
36 claims: Claims;
37 data: object;
38 signature: string;
39}
40/**
41 * Decodes a Firebase auth. token and checks the validity of its time-based claims. Will return true if the
42 * token is within the time window authorized by the 'nbf' (not-before) and 'iat' (issued-at) claims.
43 *
44 * Notes:
45 * - May return a false negative if there's no native base64 decoding support.
46 * - Doesn't check if the token is actually valid.
47 */
48export declare const isValidTimestamp: (token: string) => boolean;
49/**
50 * Decodes a Firebase auth. token and returns its issued at time if valid, null otherwise.
51 *
52 * Notes:
53 * - May return null if there's no native base64 decoding support.
54 * - Doesn't check if the token is actually valid.
55 */
56export declare const issuedAtTime: (token: string) => number | null;
57/**
58 * Decodes a Firebase auth. token and checks the validity of its format. Expects a valid issued-at time.
59 *
60 * Notes:
61 * - May return a false negative if there's no native base64 decoding support.
62 * - Doesn't check if the token is actually valid.
63 */
64export declare const isValidFormat: (token: string) => boolean;
65/**
66 * Attempts to peer into an auth token and determine if it's an admin auth token by looking at the claims portion.
67 *
68 * Notes:
69 * - May return a false negative if there's no native base64 decoding support.
70 * - Doesn't check if the token is actually valid.
71 */
72export declare const isAdmin: (token: string) => boolean;
73export {};