'use strict';

require('zod-to-json-schema');
require('zod-validation-error');
require('@backstage/errors');
var readDeclarativeSignInResolver = require('../sign-in/readDeclarativeSignInResolver.cjs.js');
require('../sign-in/commonSignInResolvers.cjs.js');
var OAuthEnvironmentHandler = require('./OAuthEnvironmentHandler.cjs.js');
var createOAuthRouteHandlers = require('./createOAuthRouteHandlers.cjs.js');

function createOAuthProviderFactory(options) {
  return (ctx) => {
    return OAuthEnvironmentHandler.OAuthEnvironmentHandler.mapConfig(ctx.config, (envConfig) => {
      const signInResolver = readDeclarativeSignInResolver.readDeclarativeSignInResolver({
        config: envConfig,
        signInResolverFactories: options.signInResolverFactories ?? {}
      }) ?? options.signInResolver;
      return createOAuthRouteHandlers.createOAuthRouteHandlers({
        authenticator: options.authenticator,
        appUrl: ctx.appUrl,
        baseUrl: ctx.baseUrl,
        config: envConfig,
        isOriginAllowed: ctx.isOriginAllowed,
        cookieConfigurer: ctx.cookieConfigurer,
        providerId: ctx.providerId,
        resolverContext: ctx.resolverContext,
        additionalScopes: options.additionalScopes,
        stateTransform: options.stateTransform,
        profileTransform: options.profileTransform,
        signInResolver
      });
    });
  };
}

exports.createOAuthProviderFactory = createOAuthProviderFactory;
//# sourceMappingURL=createOAuthProviderFactory.cjs.js.map
