From 258b410cad9825e3e87da1fe8f1c9574b82a2f98 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 8 Aug 2023 15:36:18 +0200 Subject: [PATCH] auth refactor type fixes Signed-off-by: Patrik Oldsberg --- .../auth-backend-module-gcp-iap-provider/src/module.ts | 1 + plugins/auth-backend-module-google-provider/src/module.ts | 1 + plugins/auth-backend/src/index.ts | 3 --- .../src/lib/legacy/adaptLegacyOAuthHandler.ts | 2 +- .../src/lib/legacy/adaptLegacyOAuthSignInResolver.ts | 2 +- .../src/lib/legacy/adaptOAuthSignInResolverToLegacy.ts | 1 + plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts | 2 +- .../auth-backend/src/lib/oauth/OAuthEnvironmentHandler.ts | 2 +- plugins/auth-backend/src/lib/oauth/types.ts | 2 +- plugins/auth-backend/src/providers/gcp-iap/types.ts | 2 +- .../auth-backend/src/providers/microsoft/provider.test.ts | 3 +++ plugins/auth-node/src/identity/index.ts | 2 +- plugins/auth-node/src/oauth/index.ts | 1 - plugins/auth-node/src/oauth/types.ts | 8 ++++++++ .../auth-node/src/proxy/createProxyAuthProviderFactory.ts | 1 + plugins/auth-node/src/proxy/types.ts | 2 ++ .../auth-node/src/sign-in/createSignInResolverFactory.ts | 3 +++ 17 files changed, 27 insertions(+), 11 deletions(-) diff --git a/plugins/auth-backend-module-gcp-iap-provider/src/module.ts b/plugins/auth-backend-module-gcp-iap-provider/src/module.ts index 38742e4236..90771eecb9 100644 --- a/plugins/auth-backend-module-gcp-iap-provider/src/module.ts +++ b/plugins/auth-backend-module-gcp-iap-provider/src/module.ts @@ -23,6 +23,7 @@ import { import { gcpIapAuthenticator } from './authenticator'; import { gcpIapSignInResolvers } from './resolvers'; +/** @public */ export const authModuleGcpIapProvider = createBackendModule({ pluginId: 'auth', moduleId: 'gcpIapProvider', diff --git a/plugins/auth-backend-module-google-provider/src/module.ts b/plugins/auth-backend-module-google-provider/src/module.ts index fe067c223a..0354f99880 100644 --- a/plugins/auth-backend-module-google-provider/src/module.ts +++ b/plugins/auth-backend-module-google-provider/src/module.ts @@ -23,6 +23,7 @@ import { import { googleAuthenticator } from './authenticator'; import { googleSignInResolvers } from './resolvers'; +/** @public */ export const authModuleGoogleProvider = createBackendModule({ pluginId: 'auth', moduleId: 'googleProvider', diff --git a/plugins/auth-backend/src/index.ts b/plugins/auth-backend/src/index.ts index cc6d460f3c..f8a8580359 100644 --- a/plugins/auth-backend/src/index.ts +++ b/plugins/auth-backend/src/index.ts @@ -31,9 +31,6 @@ export * from './lib/flow'; // OAuth wrapper over a passport or a custom `strategy`. export * from './lib/oauth'; -// Helpers to convert new API in @backstage/plugin-auth-node to old API -export * from './lib/legacy'; - export * from './lib/catalog'; export { getDefaultOwnershipEntityRefs } from './lib/resolvers'; diff --git a/plugins/auth-backend/src/lib/legacy/adaptLegacyOAuthHandler.ts b/plugins/auth-backend/src/lib/legacy/adaptLegacyOAuthHandler.ts index 3114306424..37f10ff184 100644 --- a/plugins/auth-backend/src/lib/legacy/adaptLegacyOAuthHandler.ts +++ b/plugins/auth-backend/src/lib/legacy/adaptLegacyOAuthHandler.ts @@ -22,7 +22,7 @@ import { AuthHandler } from '../../providers'; import { OAuthResult } from '../oauth'; import { PassportProfile } from '../passport/types'; -/** @public */ +/** @internal */ export function adaptLegacyOAuthHandler( authHandler?: AuthHandler, ): ProfileTransform> | undefined { diff --git a/plugins/auth-backend/src/lib/legacy/adaptLegacyOAuthSignInResolver.ts b/plugins/auth-backend/src/lib/legacy/adaptLegacyOAuthSignInResolver.ts index 02056c0517..e0318464ed 100644 --- a/plugins/auth-backend/src/lib/legacy/adaptLegacyOAuthSignInResolver.ts +++ b/plugins/auth-backend/src/lib/legacy/adaptLegacyOAuthSignInResolver.ts @@ -21,7 +21,7 @@ import { } from '@backstage/plugin-auth-node'; import { OAuthResult } from '../oauth'; -/** @public */ +/** @internal */ export function adaptLegacyOAuthSignInResolver( signInResolver?: SignInResolver, ): SignInResolver> | undefined { diff --git a/plugins/auth-backend/src/lib/legacy/adaptOAuthSignInResolverToLegacy.ts b/plugins/auth-backend/src/lib/legacy/adaptOAuthSignInResolverToLegacy.ts index 43b8fa2e9a..8be6049348 100644 --- a/plugins/auth-backend/src/lib/legacy/adaptOAuthSignInResolverToLegacy.ts +++ b/plugins/auth-backend/src/lib/legacy/adaptOAuthSignInResolverToLegacy.ts @@ -21,6 +21,7 @@ import { } from '@backstage/plugin-auth-node'; import { OAuthResult } from '../oauth'; +/** @internal */ export function adaptOAuthSignInResolverToLegacy< TKeys extends string, >(resolvers: { diff --git a/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts b/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts index 0e0fb2b90f..9b4afb4b2b 100644 --- a/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts +++ b/plugins/auth-backend/src/lib/oauth/OAuthAdapter.ts @@ -52,7 +52,7 @@ export const TEN_MINUTES_MS = 600 * 1000; /** * @public - * @deprecated + * @deprecated Use `createOAuthRouteHandlers` from `@backstage/plugin-auth-node` instead */ export type OAuthAdapterOptions = { providerId: string; diff --git a/plugins/auth-backend/src/lib/oauth/OAuthEnvironmentHandler.ts b/plugins/auth-backend/src/lib/oauth/OAuthEnvironmentHandler.ts index eef85f4e34..c9244eb29e 100644 --- a/plugins/auth-backend/src/lib/oauth/OAuthEnvironmentHandler.ts +++ b/plugins/auth-backend/src/lib/oauth/OAuthEnvironmentHandler.ts @@ -20,4 +20,4 @@ import { OAuthEnvironmentHandler as _OAuthEnvironmentHandler } from '@backstage/ * @public * @deprecated import from `@backstage/plugin-auth-node` instead */ -export type OAuthEnvironmentHandler = _OAuthEnvironmentHandler; +export const OAuthEnvironmentHandler = _OAuthEnvironmentHandler; diff --git a/plugins/auth-backend/src/lib/oauth/types.ts b/plugins/auth-backend/src/lib/oauth/types.ts index e91f3819c4..d133341ef4 100644 --- a/plugins/auth-backend/src/lib/oauth/types.ts +++ b/plugins/auth-backend/src/lib/oauth/types.ts @@ -26,7 +26,7 @@ import { OAuthStartResponse, ProfileInfo } from '../../providers/types'; * Common options for passport.js-based OAuth providers * * @public - * @deprecated + * @deprecated No longer in use */ export type OAuthProviderOptions = { /** diff --git a/plugins/auth-backend/src/providers/gcp-iap/types.ts b/plugins/auth-backend/src/providers/gcp-iap/types.ts index 0a88979323..b1f69318fc 100644 --- a/plugins/auth-backend/src/providers/gcp-iap/types.ts +++ b/plugins/auth-backend/src/providers/gcp-iap/types.ts @@ -32,6 +32,6 @@ export type GcpIapTokenInfo = _GcpIapTokenInfo; * callbacks. * * @public - * @deprecated + * @deprecated import from `@backstage/plugin-auth-backend-module-gcp-iap-provider` instead */ export type GcpIapResult = _GcpIapResult; diff --git a/plugins/auth-backend/src/providers/microsoft/provider.test.ts b/plugins/auth-backend/src/providers/microsoft/provider.test.ts index 6f8df2d4df..a1128ee6b9 100644 --- a/plugins/auth-backend/src/providers/microsoft/provider.test.ts +++ b/plugins/auth-backend/src/providers/microsoft/provider.test.ts @@ -45,6 +45,9 @@ describe('MicrosoftAuthProvider', () => { }, })({ providerId: 'microsoft', + baseUrl: 'http://backstage.test/api/auth', + appUrl: 'http://backstage.test', + isOriginAllowed: _ => true, globalConfig: { baseUrl: 'http://backstage.test/api/auth', appUrl: 'http://backstage.test', diff --git a/plugins/auth-node/src/identity/index.ts b/plugins/auth-node/src/identity/index.ts index 1a39c7aba3..24e2dcb691 100644 --- a/plugins/auth-node/src/identity/index.ts +++ b/plugins/auth-node/src/identity/index.ts @@ -21,4 +21,4 @@ export { type IdentityClientOptions, } from './DefaultIdentityClient'; export { IdentityClient } from './IdentityClient'; -export type { IdentityApi } from './IdentityApi'; +export type { IdentityApi, IdentityApiGetIdentityRequest } from './IdentityApi'; diff --git a/plugins/auth-node/src/oauth/index.ts b/plugins/auth-node/src/oauth/index.ts index ff07a1e6a8..25213dd2f0 100644 --- a/plugins/auth-node/src/oauth/index.ts +++ b/plugins/auth-node/src/oauth/index.ts @@ -40,6 +40,5 @@ export { type OAuthAuthenticatorRefreshInput, type OAuthAuthenticatorResult, type OAuthAuthenticatorStartInput, - type OAuthProfileTransform, type OAuthSession, } from './types'; diff --git a/plugins/auth-node/src/oauth/types.ts b/plugins/auth-node/src/oauth/types.ts index e6ddf370b6..c552de394e 100644 --- a/plugins/auth-node/src/oauth/types.ts +++ b/plugins/auth-node/src/oauth/types.ts @@ -18,6 +18,7 @@ import { Config } from '@backstage/config'; import { Request } from 'express'; import { ProfileTransform } from '../types'; +/** @public */ export interface OAuthSession { accessToken: string; tokenType: string; @@ -27,33 +28,39 @@ export interface OAuthSession { refreshToken?: string; } +/** @public */ export interface OAuthAuthenticatorStartInput { scope: string; state: string; req: Request; } +/** @public */ export interface OAuthAuthenticatorAuthenticateInput { req: Request; } +/** @public */ export interface OAuthAuthenticatorRefreshInput { scope: string; refreshToken: string; req: Request; } +/** @public */ export interface OAuthAuthenticatorLogoutInput { accessToken?: string; refreshToken?: string; req: Request; } +/** @public */ export interface OAuthAuthenticatorResult { fullProfile: TProfile; session: OAuthSession; } +/** @public */ export interface OAuthAuthenticator { defaultProfileTransform: ProfileTransform>; shouldPersistScopes?: boolean; @@ -73,6 +80,7 @@ export interface OAuthAuthenticator { logout?(input: OAuthAuthenticatorLogoutInput, ctx: TContext): Promise; } +/** @public */ export function createOAuthAuthenticator( authenticator: OAuthAuthenticator, ): OAuthAuthenticator { diff --git a/plugins/auth-node/src/proxy/createProxyAuthProviderFactory.ts b/plugins/auth-node/src/proxy/createProxyAuthProviderFactory.ts index a50225e911..8626c40b33 100644 --- a/plugins/auth-node/src/proxy/createProxyAuthProviderFactory.ts +++ b/plugins/auth-node/src/proxy/createProxyAuthProviderFactory.ts @@ -26,6 +26,7 @@ import { import { createProxyAuthRouteHandlers } from './createProxyRouteHandlers'; import { ProxyAuthenticator } from './types'; +/** @public */ export function createProxyAuthProviderFactory(options: { authenticator: ProxyAuthenticator; profileTransform?: ProfileTransform; diff --git a/plugins/auth-node/src/proxy/types.ts b/plugins/auth-node/src/proxy/types.ts index a7e0da2d4c..969b022abb 100644 --- a/plugins/auth-node/src/proxy/types.ts +++ b/plugins/auth-node/src/proxy/types.ts @@ -18,6 +18,7 @@ import { Config } from '@backstage/config'; import { Request } from 'express'; import { ProfileTransform } from '../types'; +/** @public */ export interface ProxyAuthenticator { defaultProfileTransform: ProfileTransform; initialize(ctx: { config: Config }): Promise; @@ -27,6 +28,7 @@ export interface ProxyAuthenticator { ): Promise<{ result: TResult }>; } +/** @public */ export function createProxyAuthenticator( authenticator: ProxyAuthenticator, ): ProxyAuthenticator { diff --git a/plugins/auth-node/src/sign-in/createSignInResolverFactory.ts b/plugins/auth-node/src/sign-in/createSignInResolverFactory.ts index 25e65754fe..6379eafd25 100644 --- a/plugins/auth-node/src/sign-in/createSignInResolverFactory.ts +++ b/plugins/auth-node/src/sign-in/createSignInResolverFactory.ts @@ -19,6 +19,7 @@ import { SignInResolver } from '../types'; import zodToJsonSchema from 'zod-to-json-schema'; import { JsonObject } from '@backstage/types'; +/** @public */ export interface SignInResolverFactory { ( ...options: undefined extends TOptions @@ -28,6 +29,7 @@ export interface SignInResolverFactory { optionsJsonSchema?: JsonObject; } +/** @public */ export interface SignInResolverFactoryOptions< TAuthResult, TOptionsOutput, @@ -37,6 +39,7 @@ export interface SignInResolverFactoryOptions< create(options: TOptionsOutput): SignInResolver; } +/** @public */ export function createSignInResolverFactory< TAuthResult, TOptionsOutput,