feat: treat providerInfo as a seperate return value

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-02-21 11:43:47 +01:00
parent 6f8d32f9bb
commit 9b810b9a99
10 changed files with 47 additions and 22 deletions
+7 -6
View File
@@ -173,13 +173,13 @@ export function createOAuthRouteHandlers<TProfile>(
): AuthProviderRouteHandlers;
// @public (undocumented)
export function createProxyAuthenticator<TContext, TResult>(
authenticator: ProxyAuthenticator<TContext, TResult>,
): ProxyAuthenticator<TContext, TResult>;
export function createProxyAuthenticator<TContext, TResult, TProviderInfo>(
authenticator: ProxyAuthenticator<TContext, TResult, TProviderInfo>,
): ProxyAuthenticator<TContext, TResult, TProviderInfo>;
// @public (undocumented)
export function createProxyAuthProviderFactory<TResult>(options: {
authenticator: ProxyAuthenticator<unknown, TResult>;
authenticator: ProxyAuthenticator<unknown, TResult, unknown>;
profileTransform?: ProfileTransform<TResult>;
signInResolver?: SignInResolver<TResult>;
signInResolverFactories?: Record<
@@ -538,7 +538,7 @@ export type ProfileTransform<TResult> = (
}>;
// @public (undocumented)
export interface ProxyAuthenticator<TContext, TResult> {
export interface ProxyAuthenticator<TContext, TResult, TProviderInfo> {
// (undocumented)
authenticate(
options: {
@@ -547,6 +547,7 @@ export interface ProxyAuthenticator<TContext, TResult> {
ctx: TContext,
): Promise<{
result: TResult;
providerInfo?: TProviderInfo;
}>;
// (undocumented)
defaultProfileTransform: ProfileTransform<TResult>;
@@ -557,7 +558,7 @@ export interface ProxyAuthenticator<TContext, TResult> {
// @public (undocumented)
export interface ProxyAuthRouteHandlersOptions<TResult> {
// (undocumented)
authenticator: ProxyAuthenticator<any, TResult>;
authenticator: ProxyAuthenticator<any, TResult, unknown>;
// (undocumented)
config: Config;
// (undocumented)
@@ -28,7 +28,7 @@ import { ProxyAuthenticator } from './types';
/** @public */
export function createProxyAuthProviderFactory<TResult>(options: {
authenticator: ProxyAuthenticator<unknown, TResult>;
authenticator: ProxyAuthenticator<unknown, TResult, unknown>;
profileTransform?: ProfileTransform<TResult>;
signInResolver?: SignInResolver<TResult>;
signInResolverFactories?: Record<
@@ -29,7 +29,7 @@ import { NotImplementedError } from '@backstage/errors';
/** @public */
export interface ProxyAuthRouteHandlersOptions<TResult> {
authenticator: ProxyAuthenticator<any, TResult>;
authenticator: ProxyAuthenticator<any, TResult, unknown>;
config: Config;
resolverContext: AuthResolverContext;
signInResolver: SignInResolver<TResult>;
@@ -56,7 +56,7 @@ export function createProxyAuthRouteHandlers<TResult>(
},
async refresh(this: never, req: Request, res: Response): Promise<void> {
const { result } = await authenticator.authenticate(
const { result, providerInfo } = await authenticator.authenticate(
{ req },
authenticatorCtx,
);
@@ -68,9 +68,9 @@ export function createProxyAuthRouteHandlers<TResult>(
resolverContext,
);
const response: ClientAuthResponse<{}> = {
const response: ClientAuthResponse<unknown> = {
profile,
providerInfo: {},
providerInfo,
backstageIdentity: prepareBackstageIdentityResponse(identity),
};
+5 -5
View File
@@ -19,18 +19,18 @@ import { Request } from 'express';
import { ProfileTransform } from '../types';
/** @public */
export interface ProxyAuthenticator<TContext, TResult> {
export interface ProxyAuthenticator<TContext, TResult, TProviderInfo> {
defaultProfileTransform: ProfileTransform<TResult>;
initialize(ctx: { config: Config }): TContext;
authenticate(
options: { req: Request },
ctx: TContext,
): Promise<{ result: TResult }>;
): Promise<{ result: TResult; providerInfo?: TProviderInfo }>;
}
/** @public */
export function createProxyAuthenticator<TContext, TResult>(
authenticator: ProxyAuthenticator<TContext, TResult>,
): ProxyAuthenticator<TContext, TResult> {
export function createProxyAuthenticator<TContext, TResult, TProviderInfo>(
authenticator: ProxyAuthenticator<TContext, TResult, TProviderInfo>,
): ProxyAuthenticator<TContext, TResult, TProviderInfo> {
return authenticator;
}