cookie-session: Adds Keygrip to allowed types for the cookie-session keys property (#34645)

* Adds Keygrip type to keys in  type.

* Adds test for keygrip type in cookie-session

* Adds small changes to cookie-sessions types.

* Reverts formatting because it was bloating the diff.

* Adds name to definitions-by section.

* Updates TypeScript version in header to allow imports of external types.
This commit is contained in:
Jason 2019-04-17 17:56:26 -04:00 committed by Armando Aguirre
parent e7edaf621a
commit d35eda0100
2 changed files with 17 additions and 4 deletions

View File

@ -2,6 +2,7 @@
import express = require('express');
import cookieSession = require('cookie-session');
import Keygrip = require('keygrip');
var app = express()
@ -36,4 +37,15 @@ app2.use(cookieSession({
// have a different value than the default.
app2.use(function (req, res, next) {
req.sessionOptions.maxAge = req.session['maxAge'] || req.sessionOptions.maxAge
});
});
var app3 = express()
app3.set('trust proxy', 1) // trust first proxy
// a Keygrip object may be used instead of an array of keys.
app3.use(cookieSession({
name: 'session',
keys: Keygrip(['key1', 'key2'])
}));

View File

@ -1,10 +1,11 @@
// Type definitions for cookie-session 2.0
// Project: https://github.com/expressjs/cookie-session
// Definitions by: Borislav Zhivkov <https://github.com/borislavjivkov>
// Definitions by: Borislav Zhivkov <https://github.com/borislavjivkov>, Jason Cordial <https://github.com/btomw>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.9
/// <reference types="express" />
/// <reference types="keygrip" />
declare namespace Express {
interface Request extends CookieSessionInterfaces.CookieSessionRequest {}
@ -20,7 +21,7 @@ declare namespace CookieSessionInterfaces {
/**
* The list of keys to use to sign & verify cookie values. Set cookies are always signed with keys[0], while the other keys are valid for verification, allowing for key rotation.
*/
keys?: Array<string>;
keys?: Array<string> | import('keygrip');
/**
* A string which will be used as single key if keys is not provided.