1"use strict"; 2var __importDefault = (this && this.__importDefault) || function (mod) { 3 return (mod && mod.__esModule) ? mod : { "default": mod }; 4}; 5Object.defineProperty(exports, "__esModule", { value: true }); 6exports.Issuer = void 0; 7/* 8Copyright 2022 The Sigstore Authors. 9 10Licensed under the Apache License, Version 2.0 (the "License"); 11you may not use this file except in compliance with the License. 12You may obtain a copy of the License at 13 14 http://www.apache.org/licenses/LICENSE-2.0 15 16Unless required by applicable law or agreed to in writing, software 17distributed under the License is distributed on an "AS IS" BASIS, 18WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19See the License for the specific language governing permissions and 20limitations under the License. 21*/ 22const make_fetch_happen_1 = __importDefault(require("make-fetch-happen")); 23// Standard endpoint for retrieving OpenID configuration information 24const OPENID_CONFIG_PATH = '/.well-known/openid-configuration'; 25/** 26 * The Issuer reperesents a single OAuth2 provider. 27 * 28 * The Issuer is configured with a provider's base OAuth2 endpoint which is 29 * used to retrieve the associated configuration information. 30 */ 31class Issuer { 32 constructor(baseURL) { 33 this.baseURL = baseURL; 34 this.fetch = make_fetch_happen_1.default.defaults({ retry: 2 }); 35 } 36 async authEndpoint() { 37 if (!this.config) { 38 this.config = await this.loadOpenIDConfig(); 39 } 40 return this.config.authorization_endpoint; 41 } 42 async tokenEndpoint() { 43 if (!this.config) { 44 this.config = await this.loadOpenIDConfig(); 45 } 46 return this.config.token_endpoint; 47 } 48 async loadOpenIDConfig() { 49 const url = `${this.baseURL}${OPENID_CONFIG_PATH}`; 50 return this.fetch(url).then((res) => res.json()); 51 } 52} 53exports.Issuer = Issuer; 54