From 9b810b9a9975d8f4036ff34f1a494d561c4a443b Mon Sep 17 00:00:00 2001 From: blam Date: Wed, 21 Feb 2024 11:43:47 +0100 Subject: [PATCH] feat: treat providerInfo as a seperate return value Signed-off-by: blam --- .../api-report.md | 6 +++++- .../src/authenticator.ts | 6 +++++- .../api-report.md | 3 +++ .../src/authenticator.ts | 5 ++++- .../api-report.md | 5 ++++- .../src/authenticator.ts | 11 +++++++++-- plugins/auth-node/api-report.md | 13 +++++++------ .../src/proxy/createProxyAuthProviderFactory.ts | 2 +- .../auth-node/src/proxy/createProxyRouteHandlers.ts | 8 ++++---- plugins/auth-node/src/proxy/types.ts | 10 +++++----- 10 files changed, 47 insertions(+), 22 deletions(-) diff --git a/plugins/auth-backend-module-aws-alb-provider/api-report.md b/plugins/auth-backend-module-aws-alb-provider/api-report.md index 76a366d2c9..c1f0c6f01b 100644 --- a/plugins/auth-backend-module-aws-alb-provider/api-report.md +++ b/plugins/auth-backend-module-aws-alb-provider/api-report.md @@ -21,7 +21,11 @@ export const awsAlbAuthenticator: ProxyAuthenticator< issuer: string; getKey: (header: JWTHeaderParameters) => Promise; }, - AwsAlbResult + AwsAlbResult, + { + accessToken: string; + expiresInSeconds: number; + } >; // @public diff --git a/plugins/auth-backend-module-aws-alb-provider/src/authenticator.ts b/plugins/auth-backend-module-aws-alb-provider/src/authenticator.ts index d7ca79927f..e7e0a7d76d 100644 --- a/plugins/auth-backend-module-aws-alb-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-aws-alb-provider/src/authenticator.ts @@ -81,8 +81,12 @@ export const awsAlbAuthenticator = createProxyAuthenticator({ return { result: { fullProfile, + accessToken: accessToken, + expiresInSeconds: claims.exp, + }, + providerInfo: { + accessToken: accessToken, expiresInSeconds: claims.exp, - accessToken, }, }; } catch (e) { diff --git a/plugins/auth-backend-module-gcp-iap-provider/api-report.md b/plugins/auth-backend-module-gcp-iap-provider/api-report.md index 821aa8e437..8d7c319a50 100644 --- a/plugins/auth-backend-module-gcp-iap-provider/api-report.md +++ b/plugins/auth-backend-module-gcp-iap-provider/api-report.md @@ -18,6 +18,9 @@ export const gcpIapAuthenticator: ProxyAuthenticator< jwtHeader: string; tokenValidator: (token: string) => Promise; }, + { + iapToken: GcpIapTokenInfo; + }, { iapToken: GcpIapTokenInfo; } diff --git a/plugins/auth-backend-module-gcp-iap-provider/src/authenticator.ts b/plugins/auth-backend-module-gcp-iap-provider/src/authenticator.ts index 9bb68fcbb3..7bf4290e9a 100644 --- a/plugins/auth-backend-module-gcp-iap-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-gcp-iap-provider/src/authenticator.ts @@ -47,6 +47,9 @@ export const gcpIapAuthenticator = createProxyAuthenticator({ const iapToken = await tokenValidator(token); - return { result: { iapToken } }; + return { + result: { iapToken }, + providerInfo: { iapToken }, + }; }, }); diff --git a/plugins/auth-backend-module-oauth2-proxy-provider/api-report.md b/plugins/auth-backend-module-oauth2-proxy-provider/api-report.md index 1a4c1ee6d6..1cfca55e4a 100644 --- a/plugins/auth-backend-module-oauth2-proxy-provider/api-report.md +++ b/plugins/auth-backend-module-oauth2-proxy-provider/api-report.md @@ -19,7 +19,10 @@ export const OAUTH2_PROXY_JWT_HEADER = 'X-OAUTH2-PROXY-ID-TOKEN'; // @public (undocumented) export const oauth2ProxyAuthenticator: ProxyAuthenticator< unknown, - OAuth2ProxyResult + OAuth2ProxyResult, + { + accessToken: string; + } >; // @public diff --git a/plugins/auth-backend-module-oauth2-proxy-provider/src/authenticator.ts b/plugins/auth-backend-module-oauth2-proxy-provider/src/authenticator.ts index a3da83791a..9d845d463a 100644 --- a/plugins/auth-backend-module-oauth2-proxy-provider/src/authenticator.ts +++ b/plugins/auth-backend-module-oauth2-proxy-provider/src/authenticator.ts @@ -33,7 +33,8 @@ export const OAUTH2_PROXY_JWT_HEADER = 'X-OAUTH2-PROXY-ID-TOKEN'; /** @public */ export const oauth2ProxyAuthenticator = createProxyAuthenticator< unknown, - OAuth2ProxyResult + OAuth2ProxyResult, + { accessToken: string } >({ defaultProfileTransform: async (result: OAuth2ProxyResult) => { return { @@ -63,7 +64,13 @@ export const oauth2ProxyAuthenticator = createProxyAuthenticator< return req.get(name); }, }; - return { result }; + + return { + result, + providerInfo: { + accessToken: result.accessToken, + }, + }; } catch (e) { throw new AuthenticationError('Authentication failed', e); } diff --git a/plugins/auth-node/api-report.md b/plugins/auth-node/api-report.md index 4b1a8a1f27..cf51f0f203 100644 --- a/plugins/auth-node/api-report.md +++ b/plugins/auth-node/api-report.md @@ -173,13 +173,13 @@ export function createOAuthRouteHandlers( ): AuthProviderRouteHandlers; // @public (undocumented) -export function createProxyAuthenticator( - authenticator: ProxyAuthenticator, -): ProxyAuthenticator; +export function createProxyAuthenticator( + authenticator: ProxyAuthenticator, +): ProxyAuthenticator; // @public (undocumented) export function createProxyAuthProviderFactory(options: { - authenticator: ProxyAuthenticator; + authenticator: ProxyAuthenticator; profileTransform?: ProfileTransform; signInResolver?: SignInResolver; signInResolverFactories?: Record< @@ -538,7 +538,7 @@ export type ProfileTransform = ( }>; // @public (undocumented) -export interface ProxyAuthenticator { +export interface ProxyAuthenticator { // (undocumented) authenticate( options: { @@ -547,6 +547,7 @@ export interface ProxyAuthenticator { ctx: TContext, ): Promise<{ result: TResult; + providerInfo?: TProviderInfo; }>; // (undocumented) defaultProfileTransform: ProfileTransform; @@ -557,7 +558,7 @@ export interface ProxyAuthenticator { // @public (undocumented) export interface ProxyAuthRouteHandlersOptions { // (undocumented) - authenticator: ProxyAuthenticator; + authenticator: ProxyAuthenticator; // (undocumented) config: Config; // (undocumented) diff --git a/plugins/auth-node/src/proxy/createProxyAuthProviderFactory.ts b/plugins/auth-node/src/proxy/createProxyAuthProviderFactory.ts index 8626c40b33..36e7b04e1e 100644 --- a/plugins/auth-node/src/proxy/createProxyAuthProviderFactory.ts +++ b/plugins/auth-node/src/proxy/createProxyAuthProviderFactory.ts @@ -28,7 +28,7 @@ import { ProxyAuthenticator } from './types'; /** @public */ export function createProxyAuthProviderFactory(options: { - authenticator: ProxyAuthenticator; + authenticator: ProxyAuthenticator; profileTransform?: ProfileTransform; signInResolver?: SignInResolver; signInResolverFactories?: Record< diff --git a/plugins/auth-node/src/proxy/createProxyRouteHandlers.ts b/plugins/auth-node/src/proxy/createProxyRouteHandlers.ts index 521fe39288..9aea9b27a7 100644 --- a/plugins/auth-node/src/proxy/createProxyRouteHandlers.ts +++ b/plugins/auth-node/src/proxy/createProxyRouteHandlers.ts @@ -29,7 +29,7 @@ import { NotImplementedError } from '@backstage/errors'; /** @public */ export interface ProxyAuthRouteHandlersOptions { - authenticator: ProxyAuthenticator; + authenticator: ProxyAuthenticator; config: Config; resolverContext: AuthResolverContext; signInResolver: SignInResolver; @@ -56,7 +56,7 @@ export function createProxyAuthRouteHandlers( }, async refresh(this: never, req: Request, res: Response): Promise { - const { result } = await authenticator.authenticate( + const { result, providerInfo } = await authenticator.authenticate( { req }, authenticatorCtx, ); @@ -68,9 +68,9 @@ export function createProxyAuthRouteHandlers( resolverContext, ); - const response: ClientAuthResponse<{}> = { + const response: ClientAuthResponse = { profile, - providerInfo: {}, + providerInfo, backstageIdentity: prepareBackstageIdentityResponse(identity), }; diff --git a/plugins/auth-node/src/proxy/types.ts b/plugins/auth-node/src/proxy/types.ts index 0f52feaac4..f127fc5c3f 100644 --- a/plugins/auth-node/src/proxy/types.ts +++ b/plugins/auth-node/src/proxy/types.ts @@ -19,18 +19,18 @@ import { Request } from 'express'; import { ProfileTransform } from '../types'; /** @public */ -export interface ProxyAuthenticator { +export interface ProxyAuthenticator { defaultProfileTransform: ProfileTransform; initialize(ctx: { config: Config }): TContext; authenticate( options: { req: Request }, ctx: TContext, - ): Promise<{ result: TResult }>; + ): Promise<{ result: TResult; providerInfo?: TProviderInfo }>; } /** @public */ -export function createProxyAuthenticator( - authenticator: ProxyAuthenticator, -): ProxyAuthenticator { +export function createProxyAuthenticator( + authenticator: ProxyAuthenticator, +): ProxyAuthenticator { return authenticator; }