-
Notifications
You must be signed in to change notification settings - Fork 1
Conver to ts #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conver to ts #57
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
784e6ee
add base ts changes'
bullocgr e558e2d
refactor pubkeyshelper
bullocgr 11f36ca
refactor jwtserviceauth class
bullocgr bb81b39
remove deleted service auth file
bullocgr 004df42
add service auth refactor wip
bullocgr 7d1f4fa
refactor part of jwtserviceauth-google test
bullocgr efda697
refactor jwtservice auth and tests
bullocgr 48d959e
refactor jwtauthmiddleware and tests
bullocgr d4565d7
refactor jwtdecode and tests
bullocgr b30cd8e
refactor jwtencode and test
bullocgr 263a7be
fix some linting
bullocgr 3f375bd
all tests passing
bullocgr 3dea239
linting
bullocgr d93b7d0
change bin files to ts
bullocgr c72467b
get rid of all build errors
bullocgr aa51010
conver js file to ts
bullocgr b7410e4
fix package
bullocgr 03f0e82
fix failing test
bullocgr 9f007b9
rename folder
bullocgr 708e604
remove unused interface
bullocgr 22aa8aa
export some interfaces
bullocgr ee4ecf6
revise
bullocgr b50b685
Update bin/jwtdecode.test.ts
bullocgr 56ff8e0
Update bin/jwtdecode.test.ts
bullocgr 88d7141
Update bin/jwtencode.test.ts
bullocgr 122b67e
Update bin/jwtencode.test.ts
bullocgr 98de71e
Update src/jwtserviceautherror.ts
bullocgr e8ee055
Update src/processutils.ts
bullocgr db76944
Update sample/googleoauth2v2/index.ts
bullocgr 3bcbb06
Update package.json
bullocgr e4c3d46
Update package.json
bullocgr bf11064
Update src/index.ts
bullocgr f9db093
revisions and fix build
bullocgr 79e37d9
sonar cloud build
bullocgr 4904ae1
Fix cloudbuild.yaml
chribsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./node_modules/@connectedcars/setup/.babelrc" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,5 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": [ | ||
"prettier" | ||
], | ||
"plugins": [ | ||
"prettier", | ||
"node" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 2016, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"node/no-unsupported-features": "error", | ||
"no-unused-vars": "warn", | ||
"prettier/prettier": ["error", { | ||
"singleQuote": true, | ||
"semi": false | ||
}] | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
} | ||
} | ||
"extends": "./node_modules/@connectedcars/setup/.eslintrc", | ||
// Force eslint to use local installed parser not the one from ./node_modules/@connectedcars/setup | ||
"parser": "@typescript-eslint/parser" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,5 @@ typings/ | |
.env | ||
|
||
.vscode/ | ||
.DS_Store | ||
build/ |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ARG NODE_VERSION=stable | ||
|
||
FROM gcr.io/connectedcars-staging/node-builder.master:$NODE_VERSION as builder | ||
|
||
ARG COMMIT_SHA=master | ||
|
||
WORKDIR /app | ||
|
||
USER builder | ||
|
||
# Copy application code. | ||
COPY --chown=builder:builder . /app | ||
|
||
RUN npm i | ||
RUN npm run ci-auto | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
'use strict' | ||
const { spawn } = require('child_process') | ||
const { readFileSync } = require('fs') | ||
import { spawn } from 'child_process' | ||
import { readFileSync } from 'fs' | ||
import sinon from 'sinon' | ||
|
||
const expect = require('unexpected') | ||
import { JwtUtils } from '../src/index' | ||
|
||
const { JwtUtils } = require('../src/index') | ||
const rsaPrivateKey = readFileSync(`${__dirname}/jwtencode.test.key`).toString() | ||
|
||
const rsaPrivateKey = readFileSync(`${__dirname}/jwtencode.test.key`) | ||
|
||
let jwtHeader = { | ||
const jwtHeader = { | ||
alg: 'RS256', | ||
typ: 'JWT', | ||
kid: '1' | ||
} | ||
|
||
let jwtBody = { | ||
const jwtBody = { | ||
iss: 'https://jwt.io', | ||
aud: 'localhost', | ||
sub: '[email protected]', | ||
|
@@ -24,26 +22,38 @@ let jwtBody = { | |
} | ||
|
||
describe('jwtencode', () => { | ||
it('should return ok', function(done) { | ||
this.timeout(10000) | ||
this.slow(3000) | ||
let jwtEncode = spawn(`${__dirname}/jwtdecode.js`, [ | ||
let clock: sinon.SinonFakeTimers | ||
|
||
beforeAll(async () => { | ||
clock = sinon.useFakeTimers() | ||
}) | ||
|
||
afterEach(async () => { | ||
clock.restore() | ||
}) | ||
|
||
afterAll(async () => { | ||
sinon.restore() | ||
}) | ||
it('should return ok', function (done) { | ||
clock.tick(3000) | ||
const jwtEncode = spawn(`${__dirname}/jwtdecode.js`, [ | ||
`${__dirname}/jwtencode.test.pub`, | ||
'1', | ||
'RS256', | ||
'https://jwt.io', | ||
'localhost' | ||
]) | ||
|
||
let jwt = JwtUtils.encode(rsaPrivateKey, jwtHeader, jwtBody) | ||
const jwt = JwtUtils.encode(rsaPrivateKey, jwtHeader, jwtBody) | ||
|
||
// Write JSON | ||
jwtEncode.stdin.write(jwt) | ||
jwtEncode.stdin.end() | ||
|
||
// Read stderr | ||
let stderrStr = '' | ||
let errorData = [] | ||
const errorData: any[] = [] | ||
jwtEncode.stderr.on('data', data => { | ||
errorData.push(data) | ||
}) | ||
|
@@ -53,25 +63,25 @@ describe('jwtencode', () => { | |
|
||
// Read token | ||
let stdoutStr = '' | ||
let decodedData = [] | ||
let error | ||
const decodedData: Buffer[] = [] | ||
let error: Error | ||
jwtEncode.stdout.on('data', data => { | ||
decodedData.push(data) | ||
}) | ||
jwtEncode.stdout.on('end', () => { | ||
try { | ||
stdoutStr = Buffer.concat(decodedData) | ||
.toString('utf8') | ||
.trim() | ||
let decodedBody = JSON.parse(stdoutStr) | ||
expect(decodedBody, 'to equal', jwtBody) | ||
stdoutStr = Buffer.concat(decodedData).toString('utf8').trim() | ||
const decodedBody = JSON.parse(stdoutStr) | ||
expect(decodedBody).toEqual(jwtBody) | ||
} catch (e) { | ||
error = e | ||
} | ||
}) | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
jwtEncode.on('exit', (code, signal) => { | ||
if (error) { | ||
// eslint-disable-next-line no-console | ||
console.log(`stdout:${stdoutStr}\nstderr:${stderrStr}\nexit:${code}`) | ||
done(error) | ||
} else { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env node | ||
|
||
import fs from 'fs' | ||
|
||
import { JwtUtils } from '../src' | ||
|
||
if (process.argv.length < 6) { | ||
// eslint-disable-next-line no-console | ||
console.log('jwtdecode publickeyfile keyid algo issuer audiences') | ||
process.exit(255) | ||
} | ||
const publicKeyPath = process.argv[2] | ||
const keyId = process.argv[3] | ||
const algo = process.argv[4] | ||
const issuer = process.argv[5] | ||
const audiences = process.argv[6].split(',') | ||
|
||
const publicKey = fs.readFileSync(publicKeyPath) | ||
|
||
const pubKeys = { | ||
[issuer]: { | ||
[`${keyId}@${algo}`]: publicKey.toString('utf8') | ||
} | ||
} | ||
|
||
process.stdin.resume() | ||
process.stdin.setEncoding('utf8') | ||
|
||
let buffer = '' | ||
process.stdin.on('data', function (chunk) { | ||
buffer += chunk | ||
buffer = processJwts(buffer) | ||
}) | ||
|
||
process.stdin.on('end', function () { | ||
buffer = processJwts(buffer) | ||
}) | ||
|
||
function processJwts(buffer: string): string { | ||
return buffer.replace(/(?:^|\n)\s*?([a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+)\s*?(?:$|\n)/g, (match, jwt) => { | ||
try { | ||
// eslint-disable-next-line no-console | ||
console.log(JSON.stringify(JwtUtils.decode(jwt, pubKeys, audiences), null, 2)) | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error(e.message) | ||
} | ||
return '' | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.