'use strict';

var prepareBackstageIdentityResponse = require('../identity/prepareBackstageIdentityResponse.cjs.js');
var errors = require('@backstage/errors');
require('jose');

function createProxyAuthRouteHandlers(options) {
  const { authenticator, config, resolverContext, signInResolver } = options;
  const profileTransform = options.profileTransform ?? authenticator.defaultProfileTransform;
  const authenticatorCtx = authenticator.initialize({ config });
  return {
    async start() {
      throw new errors.NotImplementedError("Not implemented");
    },
    async frameHandler() {
      throw new errors.NotImplementedError("Not implemented");
    },
    async refresh(req, res) {
      const { result, providerInfo } = await authenticator.authenticate(
        { req },
        authenticatorCtx
      );
      const { profile } = await profileTransform(result, resolverContext);
      const identity = await signInResolver(
        { profile, result },
        resolverContext
      );
      const response = {
        profile,
        providerInfo,
        backstageIdentity: prepareBackstageIdentityResponse.prepareBackstageIdentityResponse(identity)
      };
      res.status(200).json(response);
    }
  };
}

exports.createProxyAuthRouteHandlers = createProxyAuthRouteHandlers;
//# sourceMappingURL=createProxyRouteHandlers.cjs.js.map
