import{i as d,M as v,f,A as L,n as A}from"./app-JmgyQoR0.js";import{b as M,h as t,t as i,u as o,E as e,z as r,F as C,G as V,l as u,j as g,K as k,D as h,i as U,H as l}from"./vue-y3KLWBaS.js";import{M as B}from"./MkSignin-ikEPb45Z.js";import{M as E}from"./MkKeyValue-qNXtpS4q.js";import"./2fa-ubAA2qBP.js";const F={class:"_section"},S={class:"_title"},z={class:"_content"},K={class:"id"},N={class:"description"},j={class:"_content"},D={class:"_footer"},P=M({__name:"auth.form",props:{session:{}},emits:["denied","accepted"],setup(s,{emit:p}){const n=p,a=s,c=a.session.app;function m(){f("auth/deny",{token:a.session.token}).then(()=>{n("denied")})}function $(){f("auth/accept",{token:a.session.token}).then(()=>{n("accepted")})}return(y,b)=>(t(),i("section",F,[o("div",S,e(r(d).t("_auth.shareAccess",{name:r(c).name})),1),o("div",z,[o("h2",null,e(r(c).name),1),o("p",K,e(r(c).id),1),o("p",N,e(r(c).description),1)]),o("div",j,[o("h2",null,e(r(d).ts._auth.permissionAsk),1),o("ul",null,[(t(!0),i(C,null,V(r(c).permission,_=>(t(),i("li",{key:_},e(r(d).t(`_permissions.${_}`)),1))),128))])]),o("div",D,[u(v,{inline:"",onClick:m},{default:g(()=>[k(e(r(d).ts.cancel),1)]),_:1}),u(v,{inline:"",primary:"",onClick:$},{default:g(()=>[k(e(r(d).ts.accept),1)]),_:1})])]))}}),R=M({components:{XForm:P,MkSignin:B,MkKeyValue:E},props:["token"],data(){return{state:null,session:null,fetching:!0,i18n:d,auth_code:null}},mounted(){this.$i&&f("auth/session/show",{token:this.token}).then(s=>{this.session=s,this.fetching=!1,this.session.app.isAuthorized?f("auth/accept",{token:this.session.token}).then(()=>{this.accepted()}):this.state="waiting"}).catch(s=>{this.state="fetch-session-error",this.fetching=!1})},methods:{accepted(){this.state="accepted";const s=()=>window.location.search.substring(1).split("&").reduce((n,a)=>{const[c,m]=a.split("=");return n[c]=decodeURIComponent(m),n},{}),p=!!s().mastodon;if(this.session.app.callbackUrl&&p){const n=s().redirect_uri;if(!this.session.app.callbackUrl.split(`
`).some(c=>c===n))throw this.state="fetch-session-error",this.fetching=!1,console.log(`redirect uri: ${n}`),console.log(`reg_app uris: ${this.session.app.callbackUrl.split(`
`).join(",")}`),new Error("callback uri doesn't match registered app");const a=new URL(n);a.searchParams.append("code",this.session.token),s().state&&a.searchParams.append("state",s().state),location.href=a.toString()}else if(this.session.app.callbackUrl){const n=new URL(this.session.app.callbackUrl);if(["javascript:","file:","data:","mailto:","tel:"].includes(n.protocol))throw new Error("invalid url");this.session.app.callbackUrl==="urn:ietf:wg:oauth:2.0:oob"?this.auth_code=this.session.token:location.href=`${this.session.app.callbackUrl}?token=${this.session.token}&code=${this.session.token}&state=${s().state||""}`}},onLogin(s){L(s.i)}}}),X={key:0,class:""},G={key:1},H={key:1,class:"denied"},I={key:2,class:"accepted"},T={key:0},q={key:2},J={key:3,class:"error"},O={key:2,class:"signin"};function Q(s,p,n,a,c,m){const $=h("MkLoading"),y=h("XForm"),b=h("MkEllipsis"),_=h("MkKeyValue"),w=h("MkSignin");return s.$i&&s.fetching?(t(),i("div",X,[u($)])):s.$i?(t(),i("div",G,[s.state=="waiting"?(t(),U(y,{key:0,ref:"form",class:"form",session:s.session,onDenied:p[0]||(p[0]=W=>s.state="denied"),onAccepted:s.accepted},null,8,["session","onAccepted"])):l("",!0),s.state=="denied"?(t(),i("div",H,[o("h1",null,e(s.i18n.ts._auth.denied),1)])):l("",!0),s.state=="accepted"?(t(),i("div",I,[o("h1",null,e(s.session.app.isAuthorized?s.i18n.t("already-authorized"):s.i18n.ts.allowed),1),s.session.app.callbackUrl&&!s.auth_code?(t(),i("p",T,[k(e(s.i18n.ts._auth.callback),1),u(b)])):l("",!0),s.session.app.callbackUrl&&s.auth_code?(t(),U(_,{key:1,copy:s.auth_code},{key:g(()=>[k(e(s.i18n.ts._auth.copyAsk),1)]),value:g(()=>[k(e(s.auth_code),1)]),_:1},8,["copy"])):l("",!0),s.session.app.callbackUrl?l("",!0):(t(),i("p",q,e(s.i18n.ts._auth.pleaseGoBack),1))])):l("",!0),s.state=="fetch-session-error"?(t(),i("div",J,[o("p",null,e(s.i18n.ts.somethingHappened),1)])):l("",!0)])):(t(),i("div",O,[u(w,{onLogin:s.onLogin},null,8,["onLogin"])]))}const ts=A(R,[["render",Q]]);export{ts as default};
