'use strict';

var PassportHelpers = require('../passport/PassportHelpers.cjs.js');

class PassportOAuthAuthenticatorHelper {
  static defaultProfileTransform = async (input) => ({
    profile: PassportHelpers.PassportHelpers.transformProfile(
      input.fullProfile ?? {},
      input.session.idToken
    )
  });
  static from(strategy) {
    return new PassportOAuthAuthenticatorHelper(strategy);
  }
  #strategy;
  constructor(strategy) {
    this.#strategy = strategy;
  }
  async start(input, options) {
    return PassportHelpers.PassportHelpers.executeRedirectStrategy(input.req, this.#strategy, {
      scope: input.scope,
      state: input.state,
      ...options
    });
  }
  async authenticate(input, options) {
    const { result, privateInfo } = await PassportHelpers.PassportHelpers.executeFrameHandlerStrategy(input.req, this.#strategy, options);
    return {
      fullProfile: result.fullProfile,
      session: {
        accessToken: result.accessToken,
        tokenType: result.params.token_type ?? "bearer",
        scope: result.params.scope,
        expiresInSeconds: result.params.expires_in,
        idToken: result.params.id_token,
        refreshToken: privateInfo.refreshToken
      }
    };
  }
  async refresh(input) {
    const result = await PassportHelpers.PassportHelpers.executeRefreshTokenStrategy(
      this.#strategy,
      input.refreshToken,
      input.scope
    );
    const fullProfile = await this.fetchProfile(result.accessToken);
    return {
      fullProfile,
      session: {
        accessToken: result.accessToken,
        tokenType: result.params.token_type ?? "bearer",
        scope: result.params.scope,
        expiresInSeconds: result.params.expires_in,
        idToken: result.params.id_token,
        refreshToken: result.refreshToken
      }
    };
  }
  async fetchProfile(accessToken) {
    const profile = await PassportHelpers.PassportHelpers.executeFetchUserProfileStrategy(
      this.#strategy,
      accessToken
    );
    return profile;
  }
}

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