From 6e8671cf0f8b47fe69e5bddb12d55779059f703c Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 15 Jun 2020 12:13:29 +0200 Subject: [PATCH] packages/core-api: add initial definition of IdentityApi --- .../src/apis/definitions/IdentityApi.ts | 46 +++++++++++++++++++ .../core-api/src/apis/definitions/index.ts | 1 + 2 files changed, 47 insertions(+) create mode 100644 packages/core-api/src/apis/definitions/IdentityApi.ts diff --git a/packages/core-api/src/apis/definitions/IdentityApi.ts b/packages/core-api/src/apis/definitions/IdentityApi.ts new file mode 100644 index 0000000000..bbfab0ef35 --- /dev/null +++ b/packages/core-api/src/apis/definitions/IdentityApi.ts @@ -0,0 +1,46 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 { createApiRef } from '../ApiRef'; + +/** + * The Identity API used to identify and get information about the signed in user. + */ +export type IdentityApi = { + /** + * The ID of the signed in user. This ID is not meant to be presented to the user, but used + * as an opaque string to pass on to backends or use in frontend logic. + * + * TODO: The intention of the user ID is to be able to tie the user to an identity + * that is known by the catalog and/or identity backend. It should for example + * be possible to fetch all owned components using this ID. + */ + getUserId(): string; + + /** + * An OpenID Connect ID Token which proves the identity of the signed in user. + * + * The ID token will be undefined if the signed in user does not have a verified + * identity, such as a demo user or mocked user for e2e tests. + */ + getIdToken(): string | undefined; + + // TODO: getProfile(): Promise - We want this to be async when added, but needs more work. +}; + +export const identifyApiRef = createApiRef({ + id: 'core.identity', + description: 'Provides access to the identity of the signed in user', +}); diff --git a/packages/core-api/src/apis/definitions/index.ts b/packages/core-api/src/apis/definitions/index.ts index 41fbc839f9..c5d4a15117 100644 --- a/packages/core-api/src/apis/definitions/index.ts +++ b/packages/core-api/src/apis/definitions/index.ts @@ -27,5 +27,6 @@ export * from './AppThemeApi'; export * from './ConfigApi'; export * from './ErrorApi'; export * from './FeatureFlagsApi'; +export * from './IdentityApi'; export * from './OAuthRequestApi'; export * from './StorageApi';