import VirtruOIDC from './virtru-oidc.js';
export class OIDCRefreshTokenProvider {
    constructor({ clientId, externalRefreshToken, oidcOrigin, clientSecret, }) {
        if (!clientId || !externalRefreshToken) {
            throw new Error('To use this browser-only provider you must supply clientId/valid OIDC refresh token');
        }
        this.oidcAuth = new VirtruOIDC({
            clientId,
            clientSecret,
            oidcOrigin,
        });
        this.externalRefreshToken = externalRefreshToken;
    }
    async updateClientPublicKey(clientPubkey, signingKey) {
        await this.oidcAuth.refreshTokenClaimsWithClientPubkeyIfNeeded(clientPubkey, signingKey);
    }
    async withCreds(httpReq) {
        //If we've been seeded with an externally-issued refresh token, consume it
        //and exchange it for a Virtru bearer token - if it's already been consumed,
        //skip this step
        if (this.externalRefreshToken) {
            await this.oidcAuth.exchangeExternalRefreshToken(this.externalRefreshToken);
            delete this.externalRefreshToken;
        }
        return this.oidcAuth.withCreds(httpReq);
    }
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2lkYy1yZWZyZXNodG9rZW4tcHJvdmlkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvYXV0aC9vaWRjLXJlZnJlc2h0b2tlbi1wcm92aWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLFVBQVUsTUFBTSxlQUFlLENBQUM7QUFJdkMsTUFBTSxPQUFPLHdCQUF3QjtJQUluQyxZQUFZLEVBQ1YsUUFBUSxFQUNSLG9CQUFvQixFQUNwQixVQUFVLEVBQ1YsWUFBWSxHQUNjO1FBQzFCLElBQUksQ0FBQyxRQUFRLElBQUksQ0FBQyxvQkFBb0IsRUFBRTtZQUN0QyxNQUFNLElBQUksS0FBSyxDQUNiLHFGQUFxRixDQUN0RixDQUFDO1NBQ0g7UUFFRCxJQUFJLENBQUMsUUFBUSxHQUFHLElBQUksVUFBVSxDQUFDO1lBQzdCLFFBQVE7WUFDUixZQUFZO1lBQ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