Skip to content
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

Conver to ts #57

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Jul 26, 2023
e558e2d
refactor pubkeyshelper
bullocgr Jul 26, 2023
11f36ca
refactor jwtserviceauth class
bullocgr Jul 26, 2023
bb81b39
remove deleted service auth file
bullocgr Jul 26, 2023
004df42
add service auth refactor wip
bullocgr Jul 27, 2023
7d1f4fa
refactor part of jwtserviceauth-google test
bullocgr Jul 28, 2023
efda697
refactor jwtservice auth and tests
bullocgr Jul 31, 2023
48d959e
refactor jwtauthmiddleware and tests
bullocgr Jul 31, 2023
d4565d7
refactor jwtdecode and tests
bullocgr Jul 31, 2023
b30cd8e
refactor jwtencode and test
bullocgr Aug 1, 2023
263a7be
fix some linting
bullocgr Aug 1, 2023
3f375bd
all tests passing
bullocgr Aug 1, 2023
3dea239
linting
bullocgr Aug 1, 2023
d93b7d0
change bin files to ts
bullocgr Aug 1, 2023
c72467b
get rid of all build errors
bullocgr Aug 2, 2023
aa51010
conver js file to ts
bullocgr Aug 2, 2023
b7410e4
fix package
bullocgr Aug 2, 2023
03f0e82
fix failing test
bullocgr Aug 2, 2023
9f007b9
rename folder
bullocgr Aug 2, 2023
708e604
remove unused interface
bullocgr Aug 2, 2023
22aa8aa
export some interfaces
bullocgr Aug 2, 2023
ee4ecf6
revise
bullocgr Aug 3, 2023
b50b685
Update bin/jwtdecode.test.ts
bullocgr Aug 15, 2023
56ff8e0
Update bin/jwtdecode.test.ts
bullocgr Aug 15, 2023
88d7141
Update bin/jwtencode.test.ts
bullocgr Aug 15, 2023
122b67e
Update bin/jwtencode.test.ts
bullocgr Aug 15, 2023
98de71e
Update src/jwtserviceautherror.ts
bullocgr Aug 15, 2023
e8ee055
Update src/processutils.ts
bullocgr Aug 15, 2023
db76944
Update sample/googleoauth2v2/index.ts
bullocgr Aug 15, 2023
3bcbb06
Update package.json
bullocgr Aug 15, 2023
e4c3d46
Update package.json
bullocgr Aug 15, 2023
bf11064
Update src/index.ts
bullocgr Aug 15, 2023
f9db093
revisions and fix build
bullocgr Aug 16, 2023
79e37d9
sonar cloud build
bullocgr Aug 16, 2023
4904ae1
Fix cloudbuild.yaml
chribsen Aug 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/@connectedcars/setup/.babelrc"
}
29 changes: 4 additions & 25 deletions .eslintrc
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"
}
54 changes: 0 additions & 54 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ typings/
.env

.vscode/
.DS_Store
build/
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

15 changes: 15 additions & 0 deletions Dockerfile
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
bullocgr marked this conversation as resolved.
Show resolved Hide resolved
53 changes: 0 additions & 53 deletions bin/jwtdecode.js

This file was deleted.

54 changes: 32 additions & 22 deletions bin/jwtdecode.test.js → bin/jwtdecode.test.ts
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]',
Expand All @@ -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)
})
Expand All @@ -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 {
Expand Down
50 changes: 50 additions & 0 deletions bin/jwtdecode.ts
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 ''
})
}
Loading