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

- added decodedAccessToken and decodedRefreshToken to refresh token r… #51

Merged
merged 2 commits into from Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/chain-service-calls/frontend/index.ts
Expand Up @@ -68,7 +68,7 @@ app.post('/service1api1', keycloak.protect(), async (request:any, response) => {
status1Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
status1: e,
status1Token: JSON
Expand All @@ -89,7 +89,7 @@ app.post('/service1api2', keycloak.protect(), async (request:any, response) => {
status2Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
status2: e,
status2Token: JSON
Expand All @@ -110,7 +110,7 @@ app.post('/service2api', keycloak.protect(), async (request:any, response) => {
status3Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
status3: e,
status3Token: JSON
Expand All @@ -131,7 +131,7 @@ app.post('/service3api', keycloak.protect(), async (request:any, response) => {
status4Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
status4: e,
status4Token: JSON
Expand Down
4 changes: 2 additions & 2 deletions examples/chain-service-calls/service1/index.ts
Expand Up @@ -32,7 +32,7 @@ async (request:any, response) => {
});
response.json(JSON
.parse(res));
} catch (e) {
} catch (e:any) {
response.json({message: e.message});
}
});
Expand All @@ -51,7 +51,7 @@ async (request:any, response) => {
});
response.json(JSON
.parse(res));
} catch (e) {
} catch (e:any) {
response.json({message: e.message});
}
});
Expand Down
2 changes: 1 addition & 1 deletion examples/chain-service-calls/service2/authorizerUtil.ts
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
function getPolicyDocument(name:string) {
try {
return JSON.parse(fs.readFileSync(`${__dirname}/policy${name}Document.json`, 'utf8'));
} catch (e) {
} catch (e:any) {
if (e.code === 'ENOENT') {
console.error(`Expected policy${name}Document.json to be included in Lambda deployment package`);
// fallthrough
Expand Down
2 changes: 1 addition & 1 deletion examples/chain-service-calls/service2/handler.ts
Expand Up @@ -59,7 +59,7 @@ export async function auth0(event: any) {
function getDecodedToken(event: any) {
try {
return getToken(event);
} catch (e) {
} catch (e:any) {
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/chain-service-calls/service3/authorizerUtil.ts
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
function getPolicyDocument(name:string) {
try {
return JSON.parse(fs.readFileSync(`${__dirname}/policy${name}Document.json`, 'utf8'));
} catch (e) {
} catch (e:any) {
if (e.code === 'ENOENT') {
console.error(`Expected policy${name}Document.json to be included in Lambda deployment package`);
// fallthrough
Expand Down
2 changes: 1 addition & 1 deletion examples/chain-service-calls/service3/handler.ts
Expand Up @@ -61,7 +61,7 @@ export async function auth0(event: any) {
function getDecodedToken(event: any) {
try {
return getToken(event);
} catch (e) {
} catch (e:any) {
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/express-scopes/frontend/index.ts
Expand Up @@ -60,7 +60,7 @@ app.post('/express1', keycloak.protect(), async (request:any, response) => {
status1Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
status1: e,
status1Token: JSON
Expand All @@ -81,7 +81,7 @@ app.post('/express2', keycloak.protect(), async (request:any, response) => {
status2Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
status2: e,
status2Token: JSON
Expand Down
2 changes: 1 addition & 1 deletion examples/express/frontend/index.ts
Expand Up @@ -60,7 +60,7 @@ app.post('/express', keycloak.protect(), async (request:any, response) => {
status1Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
status1: e,
status1Token: JSON
Expand Down
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
function getPolicyDocument(name:string) {
try {
return JSON.parse(fs.readFileSync(`${__dirname}/policy${name}Document.json`, 'utf8'));
} catch (e) {
} catch (e:any) {
if (e.code === 'ENOENT') {
console.error(`Expected policy${name}Document.json to be included in Lambda deployment package`);
// fallthrough
Expand Down
2 changes: 1 addition & 1 deletion examples/keycloak-authorizer/serverless-jwks/handler.ts
Expand Up @@ -75,7 +75,7 @@ export async function auth0(event: any) {
function getDecodedToken(event: any) {
try {
return getToken(event);
} catch (e) {
} catch (e:any) {
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/keycloak-authorizer/serverless-jwks/rsaUtils.ts
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
function getPrivateKey() {
try {
return fs.readFileSync(`${__dirname}/server.key`, 'utf8');
} catch (e) {
} catch (e:any) {
if (e.code === 'ENOENT') {
console.log('Expected server.key to be included in Lambda deployment package');
// fallthrough
Expand All @@ -15,7 +15,7 @@ function getPrivateKey() {
export function getPublicKey() {
try {
return fs.readFileSync(`${__dirname}/server.crt`, 'utf8');
} catch (e) {
} catch (e:any) {
if (e.code === 'ENOENT') {
console.log('Expected server.key to be included in Lambda deployment package');
// fallthrough
Expand Down
2 changes: 1 addition & 1 deletion examples/keycloak-authorizer/serverless/authorizerUtil.ts
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs';
function getPolicyDocument(name:string) {
try {
return JSON.parse(fs.readFileSync(`${__dirname}/policy${name}Document.json`, 'utf8'));
} catch (e) {
} catch (e:any) {
if (e.code === 'ENOENT') {
console.error(`Expected policy${name}Document.json to be included in Lambda deployment package`);
// fallthrough
Expand Down
2 changes: 1 addition & 1 deletion examples/keycloak-authorizer/serverless/handler.ts
Expand Up @@ -65,7 +65,7 @@ export async function auth0(event: any) {
function getDecodedToken(event: any) {
try {
return getToken(event);
} catch (e) {
} catch (e:any) {
return null;
}
}
Expand Down
10 changes: 5 additions & 5 deletions examples/keycloak-authorizer/ui/index.ts
Expand Up @@ -65,7 +65,7 @@ async function clientToRPTExchange(request:any, clientId:any) {
'Content-Type': 'application/x-www-form-urlencoded',
});
return JSON.parse(response);
} catch (e) {
} catch (e:any) {
throw new Error(e);
}
}
Expand All @@ -84,7 +84,7 @@ app.post('/lambda', keycloak.protect(), keycloak.enforcer(['uiResource']), async
statusToken: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
status: e,
statusToken: JSON
Expand All @@ -107,7 +107,7 @@ app.post('/lambdaEnt', keycloak.protect(), keycloak.enforcer(['uiResource']), as
statusTokenEnt: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
statusEnt: e,
statusTokenEnt: JSON
Expand All @@ -130,7 +130,7 @@ app.post('/lambdaJwks', keycloak.protect(), keycloak.enforcer(['uiResource']), a
statusTokenJwks: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
statusJwks: e,
statusTokenJwks: JSON
Expand All @@ -152,7 +152,7 @@ app.post('/lambdaJwksEnt', keycloak.protect(), keycloak.enforcer(['uiResource'])
statusTokenJwksEnt: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
statusJwksEnt: e,
statusTokenJwksEnt: JSON
Expand Down
6 changes: 3 additions & 3 deletions examples/userToAdminAPI/frontend/index.ts
Expand Up @@ -61,7 +61,7 @@ app.post('/getUserList', keycloak.protect(), async (request:any, response) => {
status1Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
users: [{name: e}],
status1Token: JSON
Expand All @@ -85,7 +85,7 @@ app.post('/getClientList', keycloak.protect(), async (request:any, response) =>
});
clients[i].type = JSON.parse(res2).type;
clients[i].secret = JSON.parse(res2).value;
} catch (e) {
} catch (e:any) {
clients[i].secret = e;
}
}
Expand All @@ -94,7 +94,7 @@ app.post('/getClientList', keycloak.protect(), async (request:any, response) =>
status1Token: JSON
.stringify(jsonwebtoken.decode(lambdaJWT.access_token), null, 2),
});
} catch (e) {
} catch (e:any) {
renderUI(request, response, {
clients: [{name: e}],
status1Token: JSON
Expand Down
28 changes: 14 additions & 14 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "keycloak-lambda-authorizer",
"version": "1.0.6",
"version": "1.0.7",
"description": "Keycloak Cloud Adapter",
"main": "index.js",
"homepage": "https://github.com/vzakharchenko/keycloak-lambda-authorizer",
Expand Down Expand Up @@ -40,32 +40,32 @@
"author": "vzakharchenko",
"license": "Apache-2.0",
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.14.5",
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/polyfill": "^7.12.1",
"@babel/runtime": "^7.14.8",
"@babel/runtime": "^7.15.4",
"@shopify/eslint-plugin": "^40.4.0",
"@types/cookie": "^0.4.1",
"@types/cookie-parser": "^1.4.2",
"@types/jest": "^26.0.24",
"@types/jsonwebtoken": "^8.5.4",
"@types/jest": "^27.0.2",
"@types/jsonwebtoken": "^8.5.5",
"@types/jws": "^3.2.4",
"@types/node-forge": "^0.10.2",
"@types/node-forge": "^0.10.5",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"babel-eslint": "^10.1.0",
"coveralls": "^3.1.1",
"eslint": "^7.31.0",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-no-loops": "^0.3.0",
"jest": "^27.0.6",
"ts-jest": "^27.0.4",
"typescript": "^4.3.5"
"jest": "^27.2.2",
"ts-jest": "^27.0.5",
"typescript": "^4.4.3"
},
"dependencies": {
"aws-arn-parser": "^1.0.1",
"axios": "^0.21.1",
"axios": "^0.21.4",
"cookie": "^0.4.1",
"get-keycloak-public-key": "^1.0.3",
"jsonwebtoken": "^8.5.1",
Expand Down
6 changes: 3 additions & 3 deletions src/adapters/ApigatewayAdapter.test.ts
Expand Up @@ -61,7 +61,7 @@ describe('ApigatewayAdapter tests', () => {
// @ts-ignore
authorizationToken: null,
});
} catch (e) {
} catch (e:any) {
expect(e.message).toEqual('Expected \'event.authorizationToken\' parameter to be set');
error = true;
}
Expand All @@ -78,7 +78,7 @@ describe('ApigatewayAdapter tests', () => {
await new DefaultApigatewayAdapter({securityAdapter: new DummySecurityAdapter()}).validate({
authorizationToken: "JWT",
});
} catch (e) {
} catch (e:any) {
expect(e.message).toEqual('Invalid Authorization token - \'JWT\' does not match \'Bearer .*\'');
error = true;
}
Expand All @@ -95,7 +95,7 @@ describe('ApigatewayAdapter tests', () => {
await new DefaultApigatewayAdapter({securityAdapter: new DummySecurityAdapter()}).validate({
authorizationToken: "Bearer",
});
} catch (e) {
} catch (e:any) {
expect(e.message).toEqual('Invalid Authorization token - \'Bearer\' does not match \'Bearer .*\'');
error = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cache/DefaultCache.test.ts
Expand Up @@ -52,7 +52,7 @@ describe('KeycloakUtils tests', () => {
let error = false;
try {
cache.put('error', 'key', 100);
} catch (e) {
} catch (e:any) {
error = true;
expect(e.message).toEqual('Unsupported Region');
}
Expand All @@ -70,6 +70,7 @@ describe('KeycloakUtils tests', () => {
cache.get('error', 'key');
} catch (e) {
error = true;
// @ts-ignore
expect(e.message).toEqual('Unsupported Region');
}
if (!error) {
Expand Down