/*! For license information please see 1427.js.LICENSE.txt */
"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[1427],{71427:(e,t,i)=>{i.r(t),i.d(t,{Oauth2Client:()=>g});var a=i(50493),n=(i(85462),i(28362)),o=i.n(n),r=i(16682),d=i(94430),l=i(56765),s=i(60438),c=i(28120),u=i(27805),p=i(37077),h=i(77675),v=i(36179);const f="\nid\nname\ndescription\nicon\ngrantType\nclientId\nclientSecret\ncallbackUrl\nauthUrl\naccessTokenUrl\nwebhook\nusername\npassword\ncodeChallengeMethod\ncodeVerifier\nscopes\naccessToken\nrefreshToken\njwtToken\nexpires\ntokenType\nupdatedAt\ncreatedAt\n";let g=class extends((0,c.$)(h.h)(h.B4)){get context(){var e;return{title:{icon:"apps",text:null===(e=this.oauth2Client)||void 0===e?void 0:e.name}}}render(){var e=this.oauth2Client||{};return d.dy`
      <div>
        <h2><mwc-icon>apps</mwc-icon>&nbsp;${e.name||""}</h2>
        <p page-description>${e.description||""}</p>
      </div>

      <div icon>
        <img src=${e.icon}>
      </div>

      <form>
        <div fieldset-container>
          <fieldset>
            <legend>oauth2 client</legend>
            <div field-2column>
              <div field grid-span>
                <label for='name'>name</label>
                <input type='text' id="name" name="name" .value=${e.name||""}>
              </div>

              <div field grid-span>
                <label for='description'>description</label>
                <input type='text' id="description" name="description" .value=${e.description||""}>
              </div>

              <div field grid-span>
                <label for='icon'>icon</label>
                <input type='text' id="icon" name="icon" 
                  @change=${e=>this._icon=e.target.value} 
                  .value=${e.icon||""}
                >
              </div>
            </div>
          </fieldset>
        </div>

        <div fieldset-container>
          <fieldset>
            <legend>authorization</legend>
            <div field-2column>
              <div field grid-span>
                <label for='grant-type'>grant type
                  <ox-help-icon topic='/oauth2-client/grant-type'></ox-help-icon>
                </label>
                <select type='text' id="grant-type" name="grantType" .value=${e.grantType||"code"} 
                  @change=${e=>this._grantType=e.target.value}>
                  <option></option>
                  <option value='code'>Authorization Code Grant</option>
                  <option value='jwt'>JWT As Authorization Grant</option>
                  <option value='owner'>Resource Owner Password Credentials Grant</option>
                  <option value='credentials'>Client Credentials Grant</option>
                </select>
              </div>

              <div field grid-span>
                <label for='auth-url'>auth url</label>
                <input type='text' id="auth-url" name="authUrl" .value=${e.authUrl||""}>
                <div input-hint>The endpoint for authorization server. This is used to get the authorization code.</div>
              </div>

              <div field grid-span>
                <label for='access-token-url'>access token url</label>
                <input type='text' id="access-token-url" name="accessTokenUrl" .value=${e.accessTokenUrl||""}>
                <div input-hint>The endpoint for authentication server. This is used to exchange the authorization code for an access token.</div>
              </div>

              <div field grid-span>
                <label for='callback-url'>callback url</label>
                <input type='text' id="callback-url" name="callbackUrl" .value=${e.callbackUrl||""}>
                <div input-hint>This is the callback url that you will be redirected to, after your application is authorized.
                This is used to extract the authorization code or access token.
                Normally, this callback url should match the one you use during the application registration process.
                If you leave this field empty, default callback url(${location.origin}/oauth2-client/callback</label>) will be used.</div>
              </div>
              
              <div field grid-span>
                <label for='client-id'>client id</label>
                <input type='text' id="client-id" name="clientId" .value=${e.clientId||""}>
                <div input-hint>The client identifier issued to the client during the application registration process.</div>
              </div>

              <div field grid-span>
                <label for='client-secret'>client secret</label>
                <input type='text' id="client-secret" name="clientSecret" .value=${e.clientSecret||""}>
                <div input-hint>The client secret issued to the client during the application registration process.</div>
              </div>

              ${"owner"==this._grantType?d.dy`
                      <div field grid-span>
                        <label for="username">user name</label>
                        <input type="text" id="username" name="username" .value=${e.username||""} />
                      </div>

                      <div field grid-span>
                        <label for="password">password</label>
                        <input type="password" id="password" name="password" .value=${e.password||""} />
                      </div>
                    `:d.dy``}

              ${"jwt"==this._grantType?d.dy`
                      <div field grid-span>
                        <label for="jwt-token">jwt-token</label>
                        <input type="text" id="jwt-token" name="jwtToken" .value=${e.jwtToken||""} />
                        <div input-hint>The JWT Bearer Token for JWT As Authorization Grant</div>
                      </div>
                    `:d.dy``}

              <!-- code PKCE grant type not supported yet
              <div field grid-span>
                <label for='code-challenge-method'>code challenge method</label>
                <select type='text' id="code-challenge-method" name="codeChallengeMethod" .value=${e.codeChallengeMethod}>
                  <option></option>
                  <option>SHA-256</option>
                  <option>Plain</option>
                </select>
                <div input-hint>Algorithm used for generating the code challenge</div>
              </div>

              <div field grid-span>
                <label for='code-verifier'>code verifier
                  <ox-help-icon topic='/oauth2-client/code-verifier'></ox-help-icon>
                </label>
                <input type='text' id="code-verifier" name="codeVerifier" .value=${e.codeVerifier||""}>
                <div input-hint>A random, 43-128 character string used to connect the authorization request to the token request.
                Uses the following characters: [A-Z]/[a-z]/[0-9]/"-"/"."/"_"/"~".</div>
              </div>
              -->
              
              <div field grid-span>
                <label for='scopes'>scopes</label>
                <input type='text' id="scopes" name="scopes" .value=${e.scopes||""}>
                <div input-hint>The scopes of the access request. It may have multiple space-delimited values.</div>
              </div>
            </div>
          </fieldset>
        </div>

        <div fieldset-container>
          <fieldset>
            <div field grid-span>
              <label for='token-type'>token type</label>
              <input type='text' id="token-type" .value=${e.tokenType||""} readonly>
              <div input-hint>Added to the authorization header before the access token.</div>
            </div>

            <legend>access token</legend>
            <div field-2column>
              <div field grid-span>
                <label for="access-token">access token</label>
                <input id="access-token" type="text" .value=${e.accessToken||""} readonly />
                <button button-in-field clipboard-copy @click=${e=>e.preventDefault()}>copy</button>
                ${e.expires?d.dy`<div input-hint>
                        expired in ${new Date(Number(e.expires))} :
                        ${(0,s.E)(this.expTimer(e.expires))}
                      </div>`:d.dy``}
              </div>

              <div field grid-span>
                <label for="refresh-token">refresh token</label>
                <input id="refresh-token" type="text" .value=${e.refreshToken||""} readonly />
                <button button-in-field clipboard-copy @click=${e=>e.preventDefault()}>copy</button>
              </div>
            </div>
          </fieldset>
        </div>

        <button @click=${e=>this.deleteOauth2Client(e)}>delete this app</button>
        <button @click=${async e=>{e.preventDefault(),await this.updateOauth2Client(),await this.generateOauth2AccessToken()}}>get new access token</button>
        <button @click=${async e=>{e.preventDefault(),await this.updateOauth2Client(),await this.refreshOauth2AccessToken()}} ?disabled=${!e.refreshToken}>refresh access token</button>
        <input type="submit" value="update" @click=${async e=>{e.preventDefault(),await this.updateOauth2Client()}}>
      </form>
    `}updated(e){var t;e.has("oauth2Client")&&(this._grantType=null===(t=this.oauth2Client)||void 0===t?void 0:t.grantType)}firstUpdated(){this.clipboard=new(o())(this.copybuttons,{target:e=>e.parentElement.querySelector("input")})}async pageUpdated(e,t,i){this.active&&await this.fetchOauth2Client()}expTimer(e){return(0,a.FC)(this,arguments,(function*(){for(;this.active;){var t=Math.floor((Number(e)-Date.now())/1e3);const i=Math.floor(t/86400);t-=86400*i;const n=Math.floor(t/3600);t-=3600*n;const o=Math.floor(t/60),r=t-60*o;yield yield(0,a.qq)(`${i} days ${n} hours ${o} mins ${r} seconds remain`),yield(0,a.qq)((0,v._v)(1e3))}}))}async fetchOauth2Client(){const e=await u.Lp.query({query:r.ZP`
        query($id: String!) {
          oauth2Client(id: $id) {
            ${f}
          }
        }
      `,variables:{id:this.lifecycle.resourceId}});this.oauth2Client=e.data.oauth2Client}async updateOauth2Client(){const e=new FormData(this.form),t=Array.from(e.entries()).reduce(((e,[t,i])=>(e[t]=i,e)),{}),i=this.lifecycle.resourceId,a=await u.Lp.mutate({mutation:r.ZP`
        mutation($id: String!, $patch: Oauth2ClientPatch!) {
          updateOauth2Client(id: $id, patch: $patch) {
            ${f}
          }
        }
      `,variables:{id:i,patch:t}});a.errors?(0,p.h4)({level:"error",message:"update oauth2 client fail"}):this.oauth2Client=a.data.updateOauth2Client}async deleteOauth2Client(e){e.preventDefault();const t=this.lifecycle.resourceId;(await u.Lp.mutate({mutation:r.ZP`
        mutation ($id: String!) {
          deleteOauth2Client(id: $id)
        }
      `,variables:{id:t}})).errors?(0,p.h4)({level:"error",message:"delete oauth2 client fail"}):(0,h.c4)("oauth2-clients")}async generateOauth2AccessToken(){this.lifecycle.resourceId;if("code"==this.oauth2Client.grantType){const e=await u.Lp.mutate({mutation:r.ZP`
          mutation ($id: String!) {
            getOauth2AuthUrl(id: $id)
          }
        `,variables:{id:this.lifecycle.resourceId}});e.errors?(0,p.h4)({level:"error",message:"getting application access token fail"}):location.href=e.data.getOauth2AuthUrl}else{const e=await u.Lp.mutate({mutation:r.ZP`
          mutation($id: String!) {
            getOauth2AccessToken(id: $id) {
              ${f}
            }
          }
        `,variables:{id:this.lifecycle.resourceId}});e.errors?(0,p.h4)({level:"error",message:"getting application access token fail"}):(this.oauth2Client=e.data.getOauth2AccessToken,(0,p.h4)({level:"info",message:"got application access token successfully"}))}}async refreshOauth2AccessToken(){this.lifecycle.resourceId;const e=await u.Lp.mutate({mutation:r.ZP`
        mutation($id: String!) {
          refreshOauth2AccessToken(id: $id) {
            ${f}
          }
        }
      `,variables:{id:this.lifecycle.resourceId}});e.errors?(0,p.h4)({level:"error",message:"getting application access token fail"}):(this.oauth2Client=e.data.refreshOauth2AccessToken,(0,p.h4)({level:"info",message:"got application access token successfully"}))}};g.styles=[d.iv`
      :host {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        position: relative;

        background-color: var(--main-section-background-color);
        padding: var(--padding-wide);
      }
      h2 {
        margin: var(--title-margin);
        font: var(--title-font);
        color: var(--title-text-color);
      }
      [page-description] {
        margin: var(--page-description-margin);
        font: var(--page-description-font);
        color: var(--page-description-color);
      }
      [icon] {
        position: absolute;
        top: 10px;
        right: 10px;
        max-width: 80px;
      }
      [icon] img {
        max-width: 100%;
        max-height: 100%;
      }

      [button-primary] {
        background-color: var(--button-primary-background-color);
        border: var(--button-border);
        border-radius: var(--button-border-radius);
        margin: var(--button-margin);
        padding: var(--button-primary-padding);
        color: var(--button-primary-color);
        font: var(--button-primary-font);
        text-transform: var(--button-text-transform);

        text-decoration: none;
      }
      [button-primary]:hover {
        background-color: var(--button-primary-active-background-color);
        box-shadow: var(--button-active-box-shadow);
      }
      label {
        font: var(--label-font);
        color: var(--label-color);
        text-transform: var(--label-text-transform);
      }
      input,
      select {
        border: var(--border-dark-color);
        border-radius: var(--border-radius);
        margin: var(--input-margin);
        padding: var(--input-padding);
        font: var(--input-font);

        flex: 1;
      }
      select:focus,
      input:focus,
      button {
        outline: none;
      }
      form {
        max-width: var(--content-container-max-width);
      }
      [fieldset-container] {
        background-color: var(--theme-white-color);
        margin: var(--margin-wide) 0 var(--margin-default) 0;
        padding: var(--padding-default);
        border-radius: var(--border-radius);
        box-shadow: var(--box-shadow);
      }
      [fieldset-container] fieldset {
        margin: 0;
        margin-top: -15px;
      }
      fieldset {
        border-radius: var(--border-radius);
        border: var(--border-dark-color);
        margin: var(--fieldset-margin);
        padding: var(--fieldset-padding);
      }
      legend {
        padding: var(--legend-padding);
        font-weight: bold;
        color: var(--legend-color);
      }
      [field-2column] {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-gap: 15px;
      }
      [field] {
        display: flex;
        flex-direction: column;
        position: relative;
      }
      [grid-span] {
        grid-column: span 2;
      }
      button,
      input[type='submit'],
      [button-in-field] {
        background-color: var(--button-background-color);
        border: var(--button-border);
        border-radius: var(--button-border-radius);
        padding: var(--button-padding);
        color: var(--button-color);
        font: var(--button-font);
        text-transform: var(--button-text-transform);

        margin: var(--margin-default) 0 var(--margin-default) var(--margin-default);
        float: right;
        text-decoration: none;
      }
      button:hover,
      input[type='submit']:hover {
        border: var(--button-activ-border);
        box-shadow: var(--button-active-box-shadow);
      }
      [button-in-field] {
        border-radius: 0 var(--button-border-radius) var(--button-border-radius) 0;
        position: absolute;
        top: 11px;
        right: 0;
        max-height: 36px;
      }
      [input-hint] {
        font: var(--input-hint-font);
        color: var(--input-hint-color);
      }
      @media screen and (max-width: 480px) {
        [field] {
          grid-column: span 2;
        }
      }
    `],(0,a.gn)([(0,l.Cb)({type:Object}),(0,a.w6)("design:type",Object)],g.prototype,"oauth2Client",void 0),(0,a.gn)([(0,l.Cb)({type:String}),(0,a.w6)("design:type",String)],g.prototype,"_grantType",void 0),(0,a.gn)([(0,l.IO)("form"),(0,a.w6)("design:type",HTMLFormElement)],g.prototype,"form",void 0),(0,a.gn)([(0,l.Kt)("[clipboard-copy]"),(0,a.w6)("design:type",Object)],g.prototype,"copybuttons",void 0),g=(0,a.gn)([(0,l.Mo)("oauth2-client")],g)},60438:(e,t,i)=>{i.d(t,{E:()=>s});var a=i(28773),n=i(95974);class o{constructor(e){this.G=e}disconnect(){this.G=void 0}reconnect(e){this.G=e}deref(){return this.G}}class r{constructor(){this.Y=void 0,this.Z=void 0}get(){return this.Y}pause(){var e;null!==(e=this.Y)&&void 0!==e||(this.Y=new Promise((e=>this.Z=e)))}resume(){var e;null===(e=this.Z)||void 0===e||e.call(this),this.Y=this.Z=void 0}}var d=i(62987);class l extends n.sR{constructor(){super(...arguments),this._$Cq=new o(this),this._$CK=new r}render(e,t){return a.Jb}update(e,[t,i]){if(this.isConnected||this.disconnected(),t===this._$CX)return;this._$CX=t;let n=0;const{_$Cq:o,_$CK:r}=this;return(async(e,t)=>{for await(const i of e)if(!1===await t(i))return})(t,(async e=>{for(;r.get();)await r.get();const a=o.deref();if(void 0!==a){if(a._$CX!==t)return!1;void 0!==i&&(e=i(e,n)),a.commitValue(e,n),n++}return!0})),a.Jb}commitValue(e,t){this.setValue(e)}disconnected(){this._$Cq.disconnect(),this._$CK.pause()}reconnected(){this._$Cq.reconnect(this),this._$CK.resume()}}const s=(0,d.XM)(l)}}]);