diff --git a/packages/core-components/api-report.md b/packages/core-components/api-report.md index 31008624db..d57f618b57 100644 --- a/packages/core-components/api-report.md +++ b/packages/core-components/api-report.md @@ -2321,24 +2321,15 @@ export function useQueryParamState( // @public (undocumented) export function UserIcon(props: IconComponentProps): JSX.Element; -// Warning: (ae-missing-release-tag) "UserIdentity" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) +// @public export class UserIdentity implements IdentityApi { - // (undocumented) static create(options: { identity: BackstageUserIdentity; authApi: ProfileInfoApi & BackstageIdentityApi & SessionApi; profile?: ProfileInfo; - }): UserIdentity; - // Warning: (ae-forgotten-export) The symbol "GuestUserIdentity" needs to be exported by the entry point index.d.ts - // - // (undocumented) - static createGuest(): GuestUserIdentity; - // Warning: (ae-forgotten-export) The symbol "LegacyUserIdentity" needs to be exported by the entry point index.d.ts - // - // (undocumented) - static fromLegacy(result: SignInResult): LegacyUserIdentity; + }): IdentityApi; + static createGuest(): IdentityApi; + static fromLegacy(result: SignInResult): IdentityApi; // (undocumented) getBackstageIdentity(): Promise; // (undocumented) @@ -2400,5 +2391,4 @@ export type WarningPanelClassKey = // src/components/TabbedLayout/RoutedTabs.d.ts:9:5 - (ae-forgotten-export) The symbol "SubRoute" needs to be exported by the entry point index.d.ts // src/components/Table/Table.d.ts:20:5 - (ae-forgotten-export) The symbol "SelectedFilters" needs to be exported by the entry point index.d.ts // src/layout/ErrorBoundary/ErrorBoundary.d.ts:8:5 - (ae-forgotten-export) The symbol "SlackChannel" needs to be exported by the entry point index.d.ts -// src/layout/SignInPage/UserIdentity.d.ts:20:9 - (ae-unresolved-link) The @link reference could not be resolved: The package "@backstage/core-components" does not have an export "IdentityApi" ``` diff --git a/packages/core-components/src/layout/SignInPage/UserIdentity.ts b/packages/core-components/src/layout/SignInPage/UserIdentity.ts index 1461c48a49..f749711d3c 100644 --- a/packages/core-components/src/layout/SignInPage/UserIdentity.ts +++ b/packages/core-components/src/layout/SignInPage/UserIdentity.ts @@ -27,27 +27,49 @@ import { import { GuestUserIdentity } from './GuestUserIdentity'; import { LegacyUserIdentity } from './LegacyUserIdentity'; +/** + * An implementation of the IdentityApi that is constructed using + * various backstage user identity representations. + * + * @public + */ export class UserIdentity implements IdentityApi { - static createGuest() { + /** + * Creates a new IdentityApi that acts as a Guest User. + * + * @public + */ + static createGuest(): IdentityApi { return new GuestUserIdentity(); } - static fromLegacy(result: SignInResult) { + /** + * Creates a new IdentityApi using a legacy SignInResult object. + * + * @public + */ + static fromLegacy(result: SignInResult): IdentityApi { return LegacyUserIdentity.fromResult(result); } + /** + * Creates a new IdentityApi implementation using a user identity + * and an auth API that will be used to request backstage tokens. + * + * @public + */ static create(options: { identity: BackstageUserIdentity; authApi: ProfileInfoApi & BackstageIdentityApi & SessionApi; /** * Passing a profile synchronously allows the deprecated `getProfile` method to be - * called by consumers of the {@link IdentityApi}. If you do not have any consumers - * of that method then this is safe to leave out. + * called by consumers of the {@link @backstage/core-plugin-api#IdentityApi}. If you + * do not have any consumers of that method then this is safe to leave out. * * @deprecated Only provide this if you have plugins that call the synchronous `getProfile` method, which is also deprecated. */ profile?: ProfileInfo; - }) { + }): IdentityApi { return new UserIdentity(options.identity, options.authApi, options.profile); } @@ -59,6 +81,7 @@ export class UserIdentity implements IdentityApi { private readonly profile?: ProfileInfo, ) {} + /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getUserId} */ getUserId(): string { const ref = this.identity.userEntityRef; const match = /^([^:/]+:)?([^:/]+\/)?([^:/]+)$/.exec(ref); @@ -69,11 +92,13 @@ export class UserIdentity implements IdentityApi { return match[3]; } + /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getIdToken} */ async getIdToken(): Promise { const identity = await this.authApi.getBackstageIdentity(); return identity!.token; } + /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getProfile} */ getProfile(): ProfileInfo { if (!this.profile) { throw new Error( @@ -83,20 +108,24 @@ export class UserIdentity implements IdentityApi { return this.profile; } + /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getProfileInfo} */ async getProfileInfo(): Promise { const profile = await this.authApi.getProfile(); return profile!; } + /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getBackstageIdentity} */ async getBackstageIdentity(): Promise { return this.identity; } + /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.getCredentials} */ async getCredentials(): Promise<{ token?: string | undefined }> { const identity = await this.authApi.getBackstageIdentity(); return { token: identity!.token }; } + /** {@inheritdoc @backstage/core-plugin-api#IdentityApi.signOut} */ async signOut(): Promise { return this.authApi.signOut(); }