"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthClient = void 0;
const crypto_1 = __importDefault(require("crypto"));
const env_1 = require("../env/env");
class AuthClient {
    constructor() { }
    generateCodeChallenge() {
        const codeVerifier = this.base64URLEncode(crypto_1.default.randomBytes(32));
        const codeChallenge = this.base64URLEncode(this.sha256(codeVerifier));
        return { codeChallenge, codeVerifier };
    }
    base64URLEncode(input) {
        return Buffer.from(input)
            .toString('base64')
            .replace(/\+/g, '-')
            .replace(/\//g, '_')
            .replace(/=/g, '');
    }
    sha256(input) {
        return crypto_1.default.createHash('sha256').update(input).digest();
    }
    buildAuthorizationUrl(codeChallenge, redirectUri, idpType) {
        const loginQueryString = new URLSearchParams({
            codeChallenge,
            redirectUri,
            includeRefreshToken: 'true',
        }).toString();
        return idpType
            ? `${env_1.BASE_APP_URL}/authorize/social/${idpType.toLowerCase()}?${loginQueryString}`
            : `${env_1.BASE_APP_URL}/authorize?${loginQueryString}`;
    }
}
exports.AuthClient = AuthClient;
