From 50e2d6fb6ce7c4ee56b0db17ba46e06f51eb12da Mon Sep 17 00:00:00 2001 From: "Gasan.Guseinov" <465806+gusega@users.noreply.github.com> Date: Tue, 25 Mar 2025 17:11:23 +0100 Subject: [PATCH] unexport OAuth2Response Signed-off-by: Gasan.Guseinov <465806+gusega@users.noreply.github.com> --- packages/core-app-api/report.api.md | 17 -------------- .../implementations/auth/oauth2/OAuth2.ts | 18 ++++++++++++++- .../oauth2/OAuth2CustomAuthConnector.test.ts | 23 ++++++++++++++++++- .../apis/implementations/auth/oauth2/types.ts | 19 --------------- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/packages/core-app-api/report.api.md b/packages/core-app-api/report.api.md index 09119d8f8d..68dd2f05e8 100644 --- a/packages/core-app-api/report.api.md +++ b/packages/core-app-api/report.api.md @@ -21,7 +21,6 @@ import { AuthRequestOptions } from '@backstage/core-plugin-api'; import { BackstageIdentityApi } from '@backstage/core-plugin-api'; import { BackstageIdentityResponse } from '@backstage/core-plugin-api'; import { BackstagePlugin } from '@backstage/core-plugin-api'; -import { BackstageUserIdentity } from '@backstage/core-plugin-api'; import { bitbucketAuthApiRef } from '@backstage/core-plugin-api'; import { bitbucketServerAuthApiRef } from '@backstage/core-plugin-api'; import { ComponentType } from 'react'; @@ -592,22 +591,6 @@ export type OAuth2CreateOptionsWithAuthConnector = { authConnector: AuthConnector; }; -// @public (undocumented) -export type OAuth2Response = { - providerInfo: { - accessToken: string; - idToken: string; - scope: string; - expiresInSeconds?: number; - }; - profile: ProfileInfo; - backstageIdentity: { - token: string; - expiresInSeconds?: number; - identity: BackstageUserIdentity; - }; -}; - // @public export type OAuth2Session = { providerInfo: { diff --git a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts index c03176f8b6..92747a1707 100644 --- a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts +++ b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2.ts @@ -21,8 +21,10 @@ import { AuthRequestOptions, BackstageIdentityApi, BackstageIdentityResponse, + BackstageUserIdentity, OAuthApi, OpenIdConnectApi, + ProfileInfo, ProfileInfoApi, SessionApi, SessionState, @@ -31,7 +33,6 @@ import { Observable } from '@backstage/types'; import { OAuth2CreateOptions, OAuth2CreateOptionsWithAuthConnector, - OAuth2Response, OAuth2Session, } from './types'; @@ -41,6 +42,21 @@ const DEFAULT_PROVIDER = { icon: () => null, }; +export type OAuth2Response = { + providerInfo: { + accessToken: string; + idToken: string; + scope: string; + expiresInSeconds?: number; + }; + profile: ProfileInfo; + backstageIdentity: { + token: string; + expiresInSeconds?: number; + identity: BackstageUserIdentity; + }; +}; + /** * Implements a generic OAuth2 flow for auth. * diff --git a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts index 82578f835e..a3188c9a80 100644 --- a/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts +++ b/packages/core-app-api/src/apis/implementations/auth/oauth2/OAuth2CustomAuthConnector.test.ts @@ -21,9 +21,9 @@ import { AuthConnectorRefreshSessionOptions, openLoginPopup, OAuth2CreateOptionsWithAuthConnector, - OAuth2Response, } from '../../../../index'; import { waitFor } from '@testing-library/react'; +import { BackstageUserIdentity, ProfileInfo } from '@backstage/core-plugin-api'; const scopeTransform = (x: string[]) => x; @@ -34,6 +34,27 @@ type Options = { sessionTransform?(response: any): OAuth2Session | Promise; }; +/** + * A replica of private `OAuth2Response` from OAuth2.ts. + * `OAuth2Response` represents raw OAuth2 response from the `auth-backend` plugin. + * If custom auth connector calls `auth-backend` plugin, it will have to transform `OAuth2Response` into + * `OAuth2Session`. + */ +type OAuth2Response = { + providerInfo: { + accessToken: string; + idToken: string; + scope: string; + expiresInSeconds?: number; + }; + profile: ProfileInfo; + backstageIdentity: { + token: string; + expiresInSeconds?: number; + identity: BackstageUserIdentity; + }; +}; + class CustomAuthConnector implements AuthConnector { private readonly sessionTransform: (response: any) => Promise; diff --git a/packages/core-app-api/src/apis/implementations/auth/oauth2/types.ts b/packages/core-app-api/src/apis/implementations/auth/oauth2/types.ts index 0f320e97e6..651113fd4d 100644 --- a/packages/core-app-api/src/apis/implementations/auth/oauth2/types.ts +++ b/packages/core-app-api/src/apis/implementations/auth/oauth2/types.ts @@ -16,7 +16,6 @@ import { BackstageIdentityResponse, - BackstageUserIdentity, ProfileInfo, } from '@backstage/core-plugin-api'; import { OAuthApiCreateOptions } from '../types.ts'; @@ -39,24 +38,6 @@ export type OAuth2Session = { backstageIdentity?: BackstageIdentityResponse; }; -/** - * @public - */ -export type OAuth2Response = { - providerInfo: { - accessToken: string; - idToken: string; - scope: string; - expiresInSeconds?: number; - }; - profile: ProfileInfo; - backstageIdentity: { - token: string; - expiresInSeconds?: number; - identity: BackstageUserIdentity; - }; -}; - /** * OAuth2 create options. * @public