From f96679d0e6770889d3ee71e4efecdca00fcdbdc6 Mon Sep 17 00:00:00 2001 From: Nataliya Issayeva Date: Tue, 26 Oct 2021 15:47:41 -0400 Subject: [PATCH] Move IdentityClient to backend-common Signed-off-by: Nataliya Issayeva --- packages/backend-common/package.json | 2 ++ .../src/identity/IdentityClient.test.ts | 14 +++++++------- .../src/identity/IdentityClient.ts | 4 ++-- packages/backend-common/src/identity/index.ts | 17 +++++++++++++++++ packages/backend-common/src/index.ts | 1 + plugins/auth-backend/src/identity/index.ts | 2 +- plugins/auth-backend/src/index.ts | 4 ++-- 7 files changed, 32 insertions(+), 12 deletions(-) rename {plugins/auth-backend => packages/backend-common}/src/identity/IdentityClient.test.ts (97%) rename {plugins/auth-backend => packages/backend-common}/src/identity/IdentityClient.ts (97%) create mode 100644 packages/backend-common/src/identity/index.ts diff --git a/packages/backend-common/package.json b/packages/backend-common/package.json index 9e0187137d..2dbeac6845 100644 --- a/packages/backend-common/package.json +++ b/packages/backend-common/package.json @@ -34,6 +34,7 @@ "@backstage/config-loader": "^0.8.0", "@backstage/errors": "^0.1.4", "@backstage/integration": "^0.6.9", + "@backstage/plugin-auth-backend": "^0.4.5", "@backstage/types": "^0.1.1", "@google-cloud/storage": "^5.8.0", "@lerna/project": "^4.0.0", @@ -54,6 +55,7 @@ "git-url-parse": "^11.6.0", "helmet": "^4.0.0", "isomorphic-git": "^1.8.0", + "jose": "^1.27.1", "keyv": "^4.0.3", "keyv-memcache": "^1.2.5", "knex": "^0.95.1", diff --git a/plugins/auth-backend/src/identity/IdentityClient.test.ts b/packages/backend-common/src/identity/IdentityClient.test.ts similarity index 97% rename from plugins/auth-backend/src/identity/IdentityClient.test.ts rename to packages/backend-common/src/identity/IdentityClient.test.ts index 5eca6bf8cd..36d737174d 100644 --- a/plugins/auth-backend/src/identity/IdentityClient.test.ts +++ b/packages/backend-common/src/identity/IdentityClient.test.ts @@ -17,14 +17,14 @@ import { JWT, JSONWebKey } from 'jose'; import { rest } from 'msw'; import { setupServer } from 'msw/node'; -import { - getVoidLogger, - PluginEndpointDiscovery, -} from '@backstage/backend-common'; +import { getVoidLogger } from '../logging'; +import { PluginEndpointDiscovery } from '../discovery'; import { IdentityClient } from './IdentityClient'; -import { MemoryKeyStore } from './MemoryKeyStore'; -import { TokenFactory } from './TokenFactory'; -import { KeyStore } from './types'; +import { + KeyStore, + MemoryKeyStore, + TokenFactory, +} from '@backstage/plugin-auth-backend'; const logger = getVoidLogger(); diff --git a/plugins/auth-backend/src/identity/IdentityClient.ts b/packages/backend-common/src/identity/IdentityClient.ts similarity index 97% rename from plugins/auth-backend/src/identity/IdentityClient.ts rename to packages/backend-common/src/identity/IdentityClient.ts index 2af30e4b6a..b3169b02b3 100644 --- a/plugins/auth-backend/src/identity/IdentityClient.ts +++ b/packages/backend-common/src/identity/IdentityClient.ts @@ -16,8 +16,8 @@ import fetch from 'cross-fetch'; import { JWK, JWT, JWKS, JSONWebKey } from 'jose'; -import { BackstageIdentity } from '../providers'; -import { PluginEndpointDiscovery } from '@backstage/backend-common'; +import { BackstageIdentity } from '@backstage/plugin-auth-backend'; +import { PluginEndpointDiscovery } from '../discovery'; const CLOCK_MARGIN_S = 10; diff --git a/packages/backend-common/src/identity/index.ts b/packages/backend-common/src/identity/index.ts new file mode 100644 index 0000000000..67692e0ed5 --- /dev/null +++ b/packages/backend-common/src/identity/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { IdentityClient } from './IdentityClient'; diff --git a/packages/backend-common/src/index.ts b/packages/backend-common/src/index.ts index e430ddc1a4..a3c53e6f9f 100644 --- a/packages/backend-common/src/index.ts +++ b/packages/backend-common/src/index.ts @@ -25,6 +25,7 @@ export { loadBackendConfig } from './config'; export * from './database'; export * from './discovery'; export * from './hot'; +export * from './identity'; export * from './logging'; export * from './middleware'; export * from './paths'; diff --git a/plugins/auth-backend/src/identity/index.ts b/plugins/auth-backend/src/identity/index.ts index 73858d7e07..727e47ed6a 100644 --- a/plugins/auth-backend/src/identity/index.ts +++ b/plugins/auth-backend/src/identity/index.ts @@ -15,7 +15,7 @@ */ export { createOidcRouter } from './router'; -export { IdentityClient } from './IdentityClient'; +// export { IdentityClient } from './IdentityClient'; export { TokenFactory } from './TokenFactory'; export { DatabaseKeyStore } from './DatabaseKeyStore'; export { MemoryKeyStore } from './MemoryKeyStore'; diff --git a/plugins/auth-backend/src/index.ts b/plugins/auth-backend/src/index.ts index 432da00142..e348da116d 100644 --- a/plugins/auth-backend/src/index.ts +++ b/plugins/auth-backend/src/index.ts @@ -21,8 +21,8 @@ */ export * from './service/router'; -export { IdentityClient } from './identity'; -export type { TokenIssuer } from './identity'; +export { MemoryKeyStore, TokenFactory } from './identity'; +export type { KeyStore, TokenIssuer } from './identity'; export * from './providers'; // flow package provides 2 functions