async function r(e){return e.html(`
    <!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="utf-8" />
          <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
          <title>Redocly Redoc: OAuth2 Redirect</title>
      
          <style>
            .user-info {
              margin: 150px auto auto;
              width: 50%;
              background-color: whitesmoke;
              padding: 20px;
              text-align: center;
            }
          </style>
        </head>
      
        <body>
          <script>
            const d = "Something went wrong, please, try again.";
            function h(r) {
              return r && r.replace(/=+$/, "");
            }
            function w(r, e) {
              return !!r && !!e && h(r) === h(e);
            }
            const m = {
              invalid_request: "The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed.",
              invalid_client: "Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).",
              invalid_grant: "The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.",
              unauthorized_client: "The authenticated client is not authorized to use this authorization grant type.",
              unsupported_grant_type: "The authorization grant type is not supported by the authorization server.",
              invalid_scope: "The requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner.",
              // Authorization endpoint errors (from RFC 6749 Section 4.1.2.1)
              unsupported_response_type: "The requested response type is not supported by the authorization server.",
              access_denied: "The resource owner or authorization server denied the request.",
              // Token endpoint errors (from RFC 6749 Section 5.2)
              server_error: "The authorization server encountered an unexpected condition.",
              temporarily_unavailable: "The authorization server is currently unable to handle the request due to a temporary overloading or maintenance."
            };
            class i extends Error {
              error;
              error_description;
              constructor({
                message: e,
                error: t,
                error_description: n
              }) {
                const o = n || t && m[t] || t || e || d;
                super(o), this.name = "OAuth2Error", this.error = t, this.error_description = n;
              }
              static fromJsonData(e) {
                return new i({
                  error: e.error,
                  error_description: e.error_description
                });
              }
              static fromTextData(e) {
                return new i({
                  message: e
                });
              }
              static fromError(e) {
                return new i({
                  error: e.message
                });
              }
            }
            function y(r, e) {
              let t;
              const n = e ? new URL(e) : window.location;
              if (/code|token|error/.test(n.hash) ? t = n.hash.substring(1) : t = n.search.substring(1), !t)
                throw console.error("No query string in OAuth 2 redirect URL"), new i({ message: d });
              const o = new URLSearchParams(t), s = o.get("access_token"), a = o.get("code"), c = o.get("token_type"), l = o.get("expires_in"), p = o.get("state"), u = o.get("error"), g = o.get("error_description");
              if (u)
                throw new i({
                  error: u,
                  error_description: g ?? void 0
                });
              if (!w(p, r?.state))
                throw new Error("Outdated OAuth2 state");
              if (r?.flow === "implicit") {
                if (!s)
                  throw new Error(
                    \`Your OAuth2 authentication service provider redirected you without an "access_token".
            Please, try again or make sure your OAuth2 settings are correct.\`
                  );
                if (!c)
                  throw new Error(
                    \`Your OAuth2 authentication service provider redirected you without a "token_type".
            Please, try again or make sure your OAuth2 settings are correct.\`
                  );
                r?.successCallback({
                  access_token: s,
                  token_type: c,
                  expires_in: l,
                  auth_code: ""
                });
              }
              if (r?.flow === "authorizationCode") {
                if (!a)
                  throw new Error(
                    \`Your OAuth2 authentication service provider redirected you without authorization "code".
            Please, try again or make sure your OAuth2 settings are correct.\`
                  );
                r?.successCallback({
                  auth_code: a,
                  access_token: "",
                  token_type: "bearer"
                });
              }
            }
            function n() {
              const r = window.opener?.redirectOAuth2;
              try {
                y(r);
              } catch (o) {
                r?.errorCallback(o);
              }
              window.close();
            }
            window.onload = n;
          </script>
      
          <noscript> You need to enable JavaScript to run this app. </noscript>
        </body>
      </html>
    `)}export{r as replayOauth2RedirectCallbackHandler};
