auth-node: added createOAuthProviderFactory

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-07-29 11:31:00 +02:00
parent 112e45e37f
commit 987637d75a
2 changed files with 52 additions and 0 deletions
@@ -0,0 +1,51 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { AuthProviderFactory, SignInResolver } from '../types';
import { OAuthEnvironmentHandler } from './OAuthEnvironmentHandler';
import { createOAuthRouteHandlers } from './createOAuthRouteHandlers';
import { OAuthStateTransform } from './state';
import {
OAuthAuthenticator,
OAuthAuthenticatorResult,
OAuthProfileTransform,
} from './types';
/** @public */
export function createOAuthProviderFactory<TProfile>(options: {
authenticator: OAuthAuthenticator<unknown, TProfile>;
stateTransform?: OAuthStateTransform;
profileTransform?: OAuthProfileTransform<TProfile>;
signInResolver?: SignInResolver<OAuthAuthenticatorResult<TProfile>>;
}): AuthProviderFactory {
return ctx => {
return OAuthEnvironmentHandler.mapConfig(ctx.config, envConfig => {
return createOAuthRouteHandlers<TProfile>({
authenticator: options.authenticator,
appUrl: ctx.globalConfig.appUrl,
baseUrl: ctx.globalConfig.baseUrl,
config: envConfig,
isOriginAllowed: ctx.globalConfig.isOriginAllowed,
cookieConfigurer: ctx.globalConfig.cookieConfigurer,
providerId: ctx.providerId,
resolverContext: ctx.resolverContext,
stateTransform: options.stateTransform,
profileTransform: options.profileTransform,
signInResolver: options.signInResolver,
});
});
};
}
+1
View File
@@ -25,6 +25,7 @@ export {
type PassportOAuthResult,
} from './PassportOAuthAuthenticatorHelper';
export { OAuthEnvironmentHandler } from './OAuthEnvironmentHandler';
export { createOAuthProviderFactory } from './createOAuthProviderFactory';
export {
createOAuthAuthenticator,
type OAuthAuthenticator,