Skip to content

Commit 6f617e4

Browse files
committed
Merged ts-rewrite
2 parents 7723887 + afd9cc2 commit 6f617e4

34 files changed

+4027
-469
lines changed

.gitignore

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ logs
66
*.log
77
npm-debug.log*
88

9-
# Runtime data
10-
pids
11-
*.pid
12-
*.seed
13-
149
# Directory for instrumented libs generated by jscoverage/JSCover
1510
lib-cov
1611

@@ -20,9 +15,6 @@ coverage
2015
# nyc test coverage
2116
.nyc_output
2217

23-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24-
.grunt
25-
2618
# node-waf configuration
2719
.lock-wscript
2820

@@ -31,7 +23,6 @@ build/Release
3123

3224
# Dependency directories
3325
node_modules
34-
jspm_packages
3526

3627
# Optional npm cache directory
3728
.npm

.nycrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"include": [
3+
"src/*.ts",
4+
"src/**/*.ts"
5+
],
6+
"extension": [
7+
".ts"
8+
],
9+
"exclude": [
10+
"**/*.d.ts"
11+
],
12+
"require": [
13+
"ts-node/register"
14+
],
15+
"all": true
16+
}

.travis.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
language: node_js
22
node_js:
3-
- '6'
43
- 'node'
4+
- '6'
5+
6+
script: npm test
7+
8+
jobs:
9+
include:
10+
- stage: code quality
11+
script: npm run coverage:ci
12+
- script: npm run tslint

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"standard.enable": false,
3+
"tslint.enable": true
4+
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## 2.0.0 2017.08.09
7+
8+
- Complete reimplementation in TypeScript
9+
610
## 1.0.1 - 2017-04-25
711

812
- Fixes #1 (extractKeyId is rejected with SyntaxError if the JWT header is not JSON)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Coverage Status](https://coveralls.io/repos/github/vanioinformatika/node-jwt-wrapper/badge.svg?branch=master)](https://coveralls.io/github/vanioinformatika/node-jwt-wrapper?branch=master)
2+
13
# node-jwt-wrapper
24
A promisified wrapper around the jsonwebtoken npm module that handles key ids.
35
Uses bluebird promises.
@@ -28,7 +30,7 @@ function privkeyResolver (keyId) {
2830
return {key, passphrase, alg}
2931
}
3032

31-
const jwtHandler = jwt.Handler('myproject', pubkeyResolver, privkeyResolver)
33+
const jwtHandler = new jwt.JwtHandler('myproject', pubkeyResolver, privkeyResolver)
3234

3335
// Verifying JWT tokens
3436
jwtHandler.verify(jwtRaw)

dist/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { TokenExpiredError, NotBeforeError, JsonWebTokenError } from "jsonwebtoken";
2+
export { JwtHandler, PubkeyResolver, PrivkeyResolver, PubkeyData, PrivkeyData } from "./src/JwtHandler";
3+
export { MissingKeyIdError } from "./src/MissingKeyIdError";
4+
export { UnknownKeyIdError } from "./src/UnknownKeyIdError";

dist/index.js

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/JwtHandler.d.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as jwt from "jsonwebtoken";
2+
export declare type PubkeyData = {
3+
cert: string;
4+
alg: string;
5+
} | undefined | null;
6+
export declare type PrivkeyData = {
7+
key: string;
8+
passphrase: string;
9+
alg: string;
10+
} | undefined | null;
11+
export declare type PubkeyResolver = (keyId: string) => PubkeyData | Promise<PubkeyData>;
12+
export declare type PrivkeyResolver = (keyId: string) => PrivkeyData | Promise<PrivkeyData>;
13+
export declare class JwtHandler {
14+
private debug;
15+
private pubkeyResolver;
16+
private privkeyResolver;
17+
private jwtVerifyAsync;
18+
private jwtSignAsync;
19+
constructor(debugNamePrefix: string, pubkeyResolver: PubkeyResolver | null, privkeyResolver: PrivkeyResolver | null);
20+
/**
21+
* Extract key ID from the given JWT
22+
*
23+
* @param {type} jwtRaw The JWT in raw form, i.e. Base64 coded parts separated with dots
24+
* @return {Promise<string, MissingKeyIdError>} Promise to the key id
25+
*/
26+
extractKeyId(jwtRaw: string): string;
27+
/**
28+
* Validates the given JWT
29+
*
30+
* @param {string} jwtRaw The JWT in raw form, i.e. Base64 coded parts separated with dots
31+
* @param {Object} options Validation options (jsonwebtoken module options)
32+
* @return {Promise<Object, JsonWebTokenError>} Promise to the JWT body
33+
*/
34+
verify(jwtRaw: string, options?: jwt.VerifyOptions): Promise<string | object>;
35+
/**
36+
* Creates a new JWT with the given body and signs it with the given key
37+
*
38+
* @param {string} tokenBody The body of the JWT token
39+
* @param {string} keyId The ID of the signing key
40+
* @return {Promise<Object, JsonWebTokenError>} Promise to the JWT body
41+
*/
42+
create(tokenBody: object, keyId: string): Promise<string>;
43+
}

0 commit comments

Comments
 (0)