backend-{app,plugin}-api: add initial AuthService interface + implementation

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Carl-Erik Bergström <cbergstrom@spotify.com>
Co-authored-by: blam <ben@blam.sh>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-02-07 15:01:19 +01:00
parent fadb455bc1
commit c5a7cf4a4f
11 changed files with 390 additions and 0 deletions
@@ -0,0 +1,54 @@
/*
* 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.
*/
/**
* @public
*/
export type BackstageUserCredentials = {
$$type: '@backstage/BackstageCredentials';
type: 'user';
userEntityRef: string;
};
/**
* @public
*/
export type BackstageServiceCredentials = {
$$type: '@backstage/BackstageCredentials';
type: 'service';
subject: string;
};
/**
* @public
*/
export type BackstageCredentials =
| BackstageUserCredentials
| BackstageServiceCredentials;
/**
* @public
*/
export interface AuthService {
authenticate(token: string): Promise<BackstageCredentials>;
issueServiceToken(options?: {
forward?: BackstageCredentials;
}): Promise<{ token: string }>;
}
@@ -22,6 +22,15 @@ import { createServiceRef } from '../system';
* @public
*/
export namespace coreServices {
/**
* The service reference for the plugin scoped {@link IdentityService}.
*
* @public
*/
export const auth = createServiceRef<import('./AuthService').AuthService>({
id: 'core.auth',
});
/**
* The service reference for the plugin scoped {@link CacheService}.
*
@@ -15,6 +15,12 @@
*/
export { coreServices } from './coreServices';
export type {
AuthService,
BackstageCredentials,
BackstageServiceCredentials,
BackstageUserCredentials,
} from './AuthService';
export type {
CacheService,
CacheServiceOptions,