backend-plugin-api: added new core identity service

Co-authored-by: Johan Haals <johan.haals@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-11 11:48:59 +01:00
parent cd05fc32ed
commit 843a0a158c
15 changed files with 142 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-defaults': patch
---
Added factory for the new core identity service to the set of default service factories.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-app-api': patch
---
Added service factory for the new core identity service.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-plugin-api': patch
---
Added new core identity service.
+12
View File
@@ -15,6 +15,7 @@ import { ExtensionPoint } from '@backstage/backend-plugin-api';
import { HelmetOptions } from 'helmet';
import * as http from 'http';
import { HttpRouterService } from '@backstage/backend-plugin-api';
import { IdentityService } from '@backstage/backend-plugin-api';
import { LifecycleService } from '@backstage/backend-plugin-api';
import { LoggerService } from '@backstage/backend-plugin-api';
import { PermissionsService } from '@backstage/backend-plugin-api';
@@ -126,6 +127,17 @@ export type HttpServerOptions = {
};
};
// @public (undocumented)
export const identityFactory: (
options?: IdentityFactoryOptions | undefined,
) => ServiceFactory<IdentityService>;
// @public
export type IdentityFactoryOptions = {
issuer?: string;
algorithms?: string[];
};
// @public
export const lifecycleFactory: (
options?: undefined,
+1
View File
@@ -38,6 +38,7 @@
"@backstage/backend-tasks": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/errors": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"@backstage/plugin-permission-node": "workspace:^",
"@types/cors": "^2.8.6",
"@types/express": "^4.17.6",
@@ -0,0 +1,50 @@
/*
* Copyright 2022 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.
*/
import {
coreServices,
createServiceFactory,
} from '@backstage/backend-plugin-api';
import { DefaultIdentityClient } from '@backstage/plugin-auth-node';
/**
* An identity client options object which allows extra configurations
*
* @public
*/
export type IdentityFactoryOptions = {
issuer?: string;
/** JWS "alg" (Algorithm) Header Parameter values. Defaults to an array containing just ES256.
* More info on supported algorithms: https://github.com/panva/jose */
algorithms?: string[];
};
/** @public */
export const identityFactory = createServiceFactory({
service: coreServices.identity,
deps: {
config: coreServices.config,
discovery: coreServices.discovery,
tokenManager: coreServices.tokenManager,
},
async factory({}, options?: IdentityFactoryOptions) {
return async ({ discovery }) => {
return DefaultIdentityClient.create({ discovery, ...options });
};
},
});
@@ -0,0 +1,18 @@
/*
* Copyright 2023 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 { identityFactory } from './identityFactory';
export type { IdentityFactoryOptions } from './identityFactory';
@@ -19,6 +19,7 @@ export * from './config';
export * from './database';
export * from './discovery';
export * from './httpRouter';
export * from './identity';
export * from './lifecycle';
export * from './logger';
export * from './permissions';
@@ -31,6 +31,7 @@ import {
schedulerFactory,
tokenManagerFactory,
urlReaderFactory,
identityFactory,
} from '@backstage/backend-app-api';
import { ServiceFactoryOrFunction } from '@backstage/backend-plugin-api';
@@ -39,16 +40,17 @@ export const defaultServiceFactories = [
configFactory(),
databaseFactory(),
discoveryFactory(),
httpRouterFactory(),
identityFactory(),
lifecycleFactory(),
loggerFactory(),
rootLoggerFactory(),
permissionsFactory(),
rootHttpRouterFactory(),
rootLifecycleFactory(),
rootLoggerFactory(),
schedulerFactory(),
tokenManagerFactory(),
urlReaderFactory(),
httpRouterFactory(),
rootHttpRouterFactory(),
lifecycleFactory(),
rootLifecycleFactory(),
];
/**
@@ -7,6 +7,7 @@
import { Config } from '@backstage/config';
import { Handler } from 'express';
import { IdentityApi } from '@backstage/plugin-auth-node';
import { JsonValue } from '@backstage/types';
import { Knex } from 'knex';
import { PermissionEvaluator } from '@backstage/plugin-permission-common';
@@ -108,6 +109,7 @@ export namespace coreServices {
const scheduler: ServiceRef<SchedulerService, 'plugin'>;
const tokenManager: ServiceRef<TokenManagerService, 'plugin'>;
const urlReader: ServiceRef<UrlReaderService, 'plugin'>;
const identity: ServiceRef<IdentityService, 'plugin'>;
}
// @public
@@ -182,6 +184,9 @@ export interface HttpRouterService {
use(handler: Handler): void;
}
// @public (undocumented)
export interface IdentityService extends IdentityApi {}
// @public (undocumented)
export interface LifecycleService {
addShutdownHook(options: LifecycleServiceShutdownHook): void;
+1
View File
@@ -35,6 +35,7 @@
"dependencies": {
"@backstage/backend-tasks": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"@backstage/plugin-permission-common": "workspace:^",
"@backstage/types": "workspace:^",
"@types/express": "^4.17.6",
@@ -0,0 +1,20 @@
/*
* Copyright 2020 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.
*/
import { IdentityApi } from '@backstage/plugin-auth-node';
/** @public */
export interface IdentityService extends IdentityApi {}
@@ -156,4 +156,13 @@ export namespace coreServices {
export const urlReader = createServiceRef<
import('./UrlReaderService').UrlReaderService
>({ id: 'core.urlReader' });
/**
* The service reference for the plugin scoped {@link IdentityService}.
*
* @public
*/
export const identity = createServiceRef<
import('./IdentityService').IdentityService
>({ id: 'core.identity' });
}
@@ -49,3 +49,4 @@ export type {
SearchResponseFile,
UrlReaderService,
} from './UrlReaderService';
export type { IdentityService } from './IdentityService';
+2
View File
@@ -3383,6 +3383,7 @@ __metadata:
"@backstage/cli": "workspace:^"
"@backstage/config": "workspace:^"
"@backstage/errors": "workspace:^"
"@backstage/plugin-auth-node": "workspace:^"
"@backstage/plugin-permission-node": "workspace:^"
"@types/compression": ^1.7.0
"@types/cors": ^2.8.6
@@ -3516,6 +3517,7 @@ __metadata:
"@backstage/backend-tasks": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/config": "workspace:^"
"@backstage/plugin-auth-node": "workspace:^"
"@backstage/plugin-permission-common": "workspace:^"
"@backstage/types": "workspace:^"
"@types/express": ^4.17.6