Skip to content

Commit

Permalink
Merge bd49804 into 54f66b8
Browse files Browse the repository at this point in the history
  • Loading branch information
vzakharchenko committed Jul 23, 2021
2 parents 54f66b8 + bd49804 commit 3f9a603
Show file tree
Hide file tree
Showing 36 changed files with 596 additions and 286 deletions.
18 changes: 9 additions & 9 deletions examples/crossTenantReactJSExample/development/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@
"author": "",
"license": "ISC",
"dependencies": {
"antd": "^4.16.3",
"antd": "^4.16.8",
"axios": "^0.21.1",
"jsonwebtoken": "^8.5.1",
"jwa": "^2.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@craco/craco": "^6.1.2",
"@shopify/eslint-plugin": "^40.2.3",
"@types/jsonwebtoken": "^8.5.2",
"@types/react": "^17.0.11",
"@types/react-dom": "^17.0.8",
"@typescript-eslint/parser": "^4.27.0",
"@craco/craco": "^6.2.0",
"@shopify/eslint-plugin": "^40.4.0",
"@types/jsonwebtoken": "^8.5.4",
"@types/react": "^17.0.14",
"@types/react-dom": "^17.0.9",
"@typescript-eslint/parser": "^4.28.4",
"body-parser": "^1.19.0",
"cookie": "^0.4.1",
"cookie-parser": "^1.4.5",
"eslint": "^7.29.0",
"eslint": "^7.31.0",
"eslint-plugin-no-loops": "^0.3.0",
"express": "^4.17.1",
"express-session": "^1.17.2",
"keycloak-api-gateway": "../../..",
"parcel-bundler": "^1.12.5",
"typescript": "^4.3.4",
"typescript": "^4.3.5",
"webpack-manifest-plugin": "^3.1.1"
},
"browserslist": {
Expand Down
10 changes: 6 additions & 4 deletions examples/crossTenantReactJSExample/tenantSelectorApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const session = require('express-session');
const Keycloak = require('keycloak-connect');
const express = require('express');
const exphbs = require('express-handlebars');
const {serviceAccountJWT} = require('keycloak-lambda-authorizer/src/serviceAccount');
const {getKeycloakUrl, getUrl} = require('keycloak-lambda-authorizer/src/utils/restCalls');
const bodyParser = require('body-parser');
const KeycloakAdapter = require('keycloak-lambda-authorizer/dist/Adapter');
const {getKeycloakUrl,getUrl} = require('keycloak-lambda-authorizer/dist/src/utils/KeycloakUtils');

const {fetchData, sendData} = require('./restCalls');

Expand All @@ -17,6 +17,8 @@ function getMaterKeycloakJSON() {
return JSON.parse(fs.readFileSync(`${__dirname}/master-keycloak.json`, 'utf8'));
}

const serviceAccount = new KeycloakAdapter.default({keycloakJson:getMaterKeycloakJSON}).getServiceAccount();

const memoryStore = new session.MemoryStore();

app.use(session({
Expand Down Expand Up @@ -62,7 +64,7 @@ app.post('/requestAccess', keycloak.protect(), keycloak.enforcer(['Request-acces
const userName = request.kauth.grant.access_token.content.preferred_username;
const userId = request.kauth.grant.access_token.content.sub;
const keycloakJSon = getMaterKeycloakJSON();
const token = await serviceAccountJWT(keycloakJSon, {});
const token = await serviceAccount.getServiceAccountToken({request:request});
let res = await sendData(`${getKeycloakUrl(keycloakJSon)}/admin/realms/${request.query.tenant}/users`, 'POST', JSON.stringify({
enabled: false,
attributes: {},
Expand Down Expand Up @@ -92,7 +94,7 @@ app.get('/', keycloak.protect(), keycloak.enforcer(['Tenant-List']), async (requ
const userName = request.kauth.grant.access_token.content.preferred_username;
const keycloakJSon = getMaterKeycloakJSON();
try {
const token = await serviceAccountJWT(keycloakJSon, {});
const token = await serviceAccount.getServiceAccountToken({request:request});
let res = await fetchData(`${getKeycloakUrl(keycloakJSon)}/admin/realms`, 'GET', {
Authorization: `Bearer ${token}`,
});
Expand Down
18 changes: 9 additions & 9 deletions examples/multiTenantReactJSExample/development/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@
"author": "",
"license": "ISC",
"dependencies": {
"antd": "^4.16.3",
"antd": "^4.16.8",
"axios": "^0.21.1",
"jsonwebtoken": "^8.5.1",
"jwa": "^2.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@craco/craco": "^6.1.2",
"@shopify/eslint-plugin": "^40.2.3",
"@types/jsonwebtoken": "^8.5.2",
"@types/react": "^17.0.11",
"@types/react-dom": "^17.0.8",
"@typescript-eslint/parser": "^4.27.0",
"@craco/craco": "^6.2.0",
"@shopify/eslint-plugin": "^40.4.0",
"@types/jsonwebtoken": "^8.5.4",
"@types/react": "^17.0.14",
"@types/react-dom": "^17.0.9",
"@typescript-eslint/parser": "^4.28.4",
"body-parser": "^1.19.0",
"cookie": "^0.4.1",
"cookie-parser": "^1.4.5",
"eslint": "^7.29.0",
"eslint": "^7.31.0",
"eslint-plugin-no-loops": "^0.3.0",
"express": "^4.17.1",
"express-session": "^1.17.2",
"keycloak-api-gateway": "../../..",
"parcel-bundler": "^1.12.5",
"typescript": "^4.3.4",
"typescript": "^4.3.5",
"webpack-manifest-plugin": "^3.1.1"
},
"browserslist": {
Expand Down
7 changes: 4 additions & 3 deletions examples/multiTenantReactJSExample/tenantSelectorApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const path = require('path');

const express = require('express');
const exphbs = require('express-handlebars');
const {serviceAccountJWT} = require('keycloak-lambda-authorizer/src/serviceAccount');
const {getKeycloakUrl, getUrl} = require('keycloak-lambda-authorizer/src/utils/restCalls');
const KeycloakAdapter = require('keycloak-lambda-authorizer/dist/Adapter');
const {getKeycloakUrl, getUrl} = require('keycloak-lambda-authorizer/dist/src/utils/KeycloakUtils');
const bodyParser = require('body-parser');

const {fetchData, sendData} = require('./restCalls');
Expand All @@ -15,6 +15,7 @@ function getKeycloakJSON() {
return JSON.parse(fs.readFileSync(`${__dirname}/keycloak.json`, 'utf8'));
}

const serviceAccount = new KeycloakAdapter.default({keycloakJson:getKeycloakJSON,}).getServiceAccount();
app.use(bodyParser.urlencoded({extended: true}));

app.engine('.hbs', exphbs({
Expand Down Expand Up @@ -43,7 +44,7 @@ app.get('/', async (request, response) => {

const keycloakJSon = getKeycloakJSON();
try {
const token = await serviceAccountJWT(keycloakJSon, {});
const token = await serviceAccount.getServiceAccountToken({request});
let res = await fetchData(`${getKeycloakUrl(keycloakJSon)}/admin/realms`, 'GET', {
Authorization: `Bearer ${token}`,
});
Expand Down
12 changes: 6 additions & 6 deletions examples/reactJSExample/development/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
},
"devDependencies": {
"@craco/craco": "^6.1.2",
"@shopify/eslint-plugin": "^40.2.3",
"@types/jsonwebtoken": "^8.5.2",
"@types/react": "^17.0.11",
"@types/react-dom": "^17.0.8",
"@typescript-eslint/parser": "^4.27.0",
"body-parser": "^1.19.0",
"keycloak-api-gateway": "../../..",
"cookie": "^0.4.1",
"cookie-parser": "^1.4.5",
"eslint": "^7.29.0",
"eslint-plugin-no-loops": "^0.3.0",
"express": "^4.17.1",
"express-session": "^1.17.2",
"keycloak-api-gateway": "../../..",
"parcel-bundler": "^1.12.5",
"typescript": "^4.3.4",
"webpack-manifest-plugin": "^3.1.1",
"@shopify/eslint-plugin": "^40.2.3",
"@typescript-eslint/parser": "^4.27.0",
"eslint": "^7.29.0",
"eslint-plugin-no-loops": "^0.3.0"
"webpack-manifest-plugin": "^3.1.1"
},
"browserslist": {
"production": [
Expand Down
24 changes: 15 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "keycloak-api-gateway",
"version": "0.2.1",
"version": "1.0.1",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -17,7 +17,12 @@
"keycloak",
"api",
"gateway",
"api-gateway"
"cloudfront",
"lambda:edge",
"lambda@edge",
"api-gateway",
"multi-tenant",
"multitenant"
],
"author": "vzakharchenko",
"license": "Apache-2.0",
Expand All @@ -26,25 +31,26 @@
},
"homepage": "https://github.com/vzakharchenko/keycloak-api-gateway#readme",
"devDependencies": {
"@shopify/eslint-plugin": "^40.3.0",
"@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/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"coveralls": "^3.1.1",
"eslint": "^7.30.0",
"eslint": "^7.31.0",
"eslint-plugin-no-loops": "^0.3.0",
"jest": "^27.0.6",
"ts-jest": "^27.0.3",
"ts-jest": "^27.0.4",
"typescript": "^4.3.5"
},
"dependencies": {
"aws-sdk": "^2.940.0",
"aws-sdk": "^2.952.0",
"jsonwebtoken": "^8.5.1",
"keycloak-lambda-authorizer": "^0.5.2",
"jws": "^4.0.0",
"keycloak-lambda-authorizer": "1.0.1",
"uuid": "^8.3.2"
},
"optionalDependencies": {
Expand Down
10 changes: 7 additions & 3 deletions src/apigateway/ApiGateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {AccessLevel, Options, RequestObject, ResponseObject} from "../index";
import {initOptions} from "../utils/DefaultPageHandlers";
import {Logout} from "../logout/Logout";
import {Callback} from "../callback/Callback";
import {JWKS} from "../jwks/JWKS";
import {UrlJWKS} from "../jwks/UrlJWKS";
import {TenantAdapter} from "../tenant/TenantAdapter";
import {MultiTenantAdapter} from "../multitenants/Multi-tenant-adapter";
import {getCustomPageHandler} from "../utils/KeycloakUtils";
Expand Down Expand Up @@ -61,7 +61,7 @@ export class DummyLogout implements Logout {
}
}

export class DummyJWKS implements JWKS {
export class DummyJWKS implements UrlJWKS {
private isRequest: boolean;

constructor(isRequest: boolean) {
Expand All @@ -72,7 +72,7 @@ export class DummyJWKS implements JWKS {
return this.isRequest;
}

async jwks(req: RequestObject, res: ResponseObject): Promise<void> {
async getPublicKey(req: RequestObject, res: ResponseObject): Promise<void> {
throw new Error('jwks');
}

Expand Down Expand Up @@ -245,6 +245,7 @@ describe('ApiGateway tests', () => {
});

test('test singleTenant error2', async () => {
// @ts-ignore
const apiGateway = new DefaultApiGateway({
...options,
...{
Expand All @@ -268,6 +269,7 @@ describe('ApiGateway tests', () => {
});

test('test singleTenant', async () => {
// @ts-ignore
const apiGateway = new DefaultApiGateway({
...options,
...{
Expand Down Expand Up @@ -303,6 +305,7 @@ describe('ApiGateway tests', () => {
},
};
});
// @ts-ignore
const apiGateway = new DefaultApiGateway({
...options,
...{
Expand Down Expand Up @@ -338,6 +341,7 @@ describe('ApiGateway tests', () => {
}
return null;
});
// @ts-ignore
const apiGateway = new DefaultApiGateway({
...options,
...{
Expand Down
14 changes: 7 additions & 7 deletions src/apigateway/ApiGateway.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {AdapterContent, KeycloakJsonStructure, AdapterDependencies} from "keycloak-lambda-authorizer/dist/src/Options";

import {getSessionToken, SessionTokenKeys} from "../session/SessionManager";
import {IdentityProviders, Options, RequestObject, ResponseObject} from "../index";
import {IdentityProviders, MultitenantAdapterDependencies, Options, RequestObject, ResponseObject} from "../index";
import {DynamoDbSettings} from "../session/storage/DynamoDB";
import {getCustomPageHandler, getSessionName} from "../utils/KeycloakUtils";
import {initOptions} from "../utils/DefaultPageHandlers";
Expand All @@ -8,11 +10,9 @@ import {StrorageDB} from "../session/storage/Strorage";


export type APIGateWayOptions = {
multiTenantJson?: (tenant: string) => Promise<any> | any;
// eslint-disable-next-line no-warning-comments, line-comment-position
multiTenantAdapterOptions?: any; // todo
// eslint-disable-next-line no-warning-comments, line-comment-position
defaultAdapterOptions?: any; // todo
multiTenantJson?: (tenant: string) => Promise<KeycloakJsonStructure> | KeycloakJsonStructure;
multiTenantAdapterOptions?: MultitenantAdapterDependencies;
defaultAdapterOptions?: AdapterDependencies;
identityProviders?: IdentityProviders;
pageHandlers?: PageHandlers;
storageType: 'InMemoryDB'|'DynamoDB' | StrorageDB,
Expand Down Expand Up @@ -62,7 +62,7 @@ export class DefaultApiGateway implements ApiGateway {
return;
}
if (this.options.jwks.isJwksRoute(request)) {
await this.options.jwks.jwks(request, response);
await this.options.jwks.getPublicKey(request, response);
return;
}
if (this.options.callback.isCallBack(request)) {
Expand Down
Loading

0 comments on commit 3f9a603

Please sign in to comment.