From 33b2dc7ab86a8c9bacb8b402ec6ebe15a5702c01 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 22 Aug 2021 12:41:13 +0200 Subject: [PATCH] integrations-react: add ScmAuthApi Signed-off-by: Patrik Oldsberg --- .../integration-react/src/api/ScmAuthApi.ts | 78 +++++++++++++++++++ packages/integration-react/src/api/index.ts | 6 ++ 2 files changed, 84 insertions(+) create mode 100644 packages/integration-react/src/api/ScmAuthApi.ts diff --git a/packages/integration-react/src/api/ScmAuthApi.ts b/packages/integration-react/src/api/ScmAuthApi.ts new file mode 100644 index 0000000000..9a20ae9a9e --- /dev/null +++ b/packages/integration-react/src/api/ScmAuthApi.ts @@ -0,0 +1,78 @@ +/* + * 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 { + ApiRef, + createApiRef, + AuthRequestOptions, +} from '@backstage/core-plugin-api'; + +export interface ScmAuthTokenOptions extends AuthRequestOptions { + /** + * The URL of the SCM resource to be accessed. + * + * @example https://github.com/backstage/backstage + */ + url: string; + + /** + * The type of access to be granted. + */ + scope: { + /** + * Whether to request access to be able to read repository content, including + * read access to management features like issues and pull requests. + */ + repoRead?: boolean; + + /** + * Whether to request access to be able to write repository content, including + * the ability to create management features like issues and pull requests. + */ + repoWrite?: boolean; + }; +} + +export interface ScmAuthTokenResponse { + /** + * An authorization token that can be used to authenticate requests. + */ + token: string; + + /** + * The set of HTTP headers that are needed to authenticate requests. + */ + headers: { [name: string]: string }; +} + +/** + * ScmAuthApi provides methods for authenticating towards source code management services. + * + * As opposed to using the using the GitHub, GitLab and other auth APIs + * directly, this API allows for more generic access to SCM services. + */ +export interface ScmAuthApi { + /** + * Requests credentials for accessing an SCM resource. + */ + getCredentials( + options: ScmAuthTokenOptions, + ): Promise; +} + +export const scmAuthApiRef: ApiRef = createApiRef({ + id: 'core.scmauth', +}); diff --git a/packages/integration-react/src/api/index.ts b/packages/integration-react/src/api/index.ts index 7417bd0c7b..1c92ba0e3b 100644 --- a/packages/integration-react/src/api/index.ts +++ b/packages/integration-react/src/api/index.ts @@ -14,6 +14,12 @@ * limitations under the License. */ +export { scmAuthApiRef } from './ScmAuthApi'; +export type { + ScmAuthApi, + ScmAuthTokenOptions, + ScmAuthTokenResponse, +} from './ScmAuthApi'; export { ScmIntegrationsApi, scmIntegrationsApiRef,