-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.d.ts
76 lines (65 loc) · 2.34 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Type definitions for express-bearer-token 2.1.1
// Project: https://github.com/tkellen/js-express-bearer-token
// Definitions by: Jan-Joost den Brinker <https://github.com/jjdbrinker>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
/* =================== USAGE ===================
import * as bearerToken from "express-bearer-token";
app.use(bearerToken({
bodyKey: 'access_token',
queryKey: 'access_token',
headerKey: 'Bearer',
reqKey: 'token'
}));
=============================================== */
import * as express from "express";
/**
* This module will attempt to extract a bearer token from a request from these locations:
* - The key access_token in the request body.
* - The key access_token in the request params.
* - The value from the header Authorization: Bearer <token>.
* - Will check headers cookies if has any 'access_token=TOKEN;'
*
* If a token is found, it will be stored on req.token.
* If a token has been provided in more than one location, the request will be aborted immediately with HTTP status code 400 (per RFC6750).
*
* To change the variables used by this module, you can specify an object with new options.
*/
declare function bearerToken(options?: bearerToken.BearerTokenOptions): express.Handler;
declare namespace bearerToken {
interface BearerTokenOptions {
/**
* Specify the key that will be used to find the token in the request body.
*/
bodyKey?: string;
/**
* Specify the key that will be used to find the token in the request params.
*/
queryKey? : string;
/**
* Specify the value that will be used to find the token in the request header.
*/
headerKey?: string;
/**
* Specify the key that will be used to bind the token to (if found on the request).
*/
reqKey?: string;
/**
* Specify cookie options with key, AND if is signed, pass a secret.
*/
cookie?: {
signed: boolean,
key: string,
secret: string,
};
}
function bearerToken(options?: BearerTokenOptions): express.Handler;
}
declare global {
namespace Express {
export interface Request {
token?: string
}
}
}
export = bearerToken;