import{f as T,n as k,q as P,y as S,z as C,s as l,v as u,x as _,k as E,_ as I,o as h,c as f,a as t,t as a,d,aq as R,ar as $,W as g}from"./entry.c7cd0af6.js";import{m as U}from"./index.20c05cdd.js";import{u as m}from"./api.45358b0b.js";function j(e,s){const n=Array.isArray(s)?s:[s];for(let i=0;i<n.length;i++)if(U(e,n[i]))return!0;return!1}function N(e){if(typeof e.client_id!="string"||!e.client_id||e.client_id.length===0)throw new Error("The client_id is invalid");if(typeof e.redirect_uri!="string"||!e.redirect_uri||e.redirect_uri.length===0)throw new Error("The redirect_uri is invalid");if(typeof e.response_type>"u"&&(e.response_type="code"),typeof e.response_type!="string"||e.response_type.length===0)throw new Error("The response_type is invalid");return typeof e.scope>"u"&&(e.scope=""),Array.isArray(e.scope)&&(e.scope=e.scope.join(" ")),{client_id:decodeURIComponent(e.client_id),response_type:e.response_type,redirect_uri:decodeURIComponent(e.redirect_uri),scope:decodeURIComponent(e.scope||"")}}const B=T({async setup(){let e,s;const n=k(),i=P(),v=S(),{loggedIn:y}=C(v);if(!y.value)throw[e,s]=l(()=>u({path:"/login",query:{...i.query,redirect:i.path}})),await e,s(),_({});const o=N(i.query),c=E(null);try{c.value=([e,s]=l(()=>m().client.getOne(o.client_id)),e=await e,s(),e)}catch{throw[e,s]=l(()=>u({path:"/authorize-error",query:{message:"The client_id is invalid."}})),await e,s(),_({})}const b=(c.value.redirect_uri||"").split(",");if(!j(o.redirect_uri,b))throw[e,s]=l(()=>u({path:"/authorize-error",query:{message:"The redirect_uri does not match."}})),await e,s(),_({});let p=[];typeof o.scope=="string"&&o.scope.length>0&&(p=o.scope.split(" "));const x={filter:{client_id:c.value.id,...p.length>0?{scope:{name:p}}:{}},relations:["scope"]},{data:w}=([e,s]=l(()=>m().clientScope.getMany(x)),e=await e,s(),e);return{abort:()=>{const r=new URL(`${o.redirect_uri}`);r.searchParams.set("error","access_denied"),r.searchParams.set("error_description","The resource owner or authorization server denied the request"),i.query.state&&typeof i.query.state=="string"&&r.searchParams.set("state",i.query.state),window.location.href=r.href},authorize:async()=>{try{const r=await m().post("authorize",{response_type:o.response_type,client_id:c.value.id,redirect_uri:o.redirect_uri,...i.query.state?{state:i.query.state}:{},scope:w.map(A=>A.scope.name).join(" ")}),{url:z}=r.data;window.location.href=z}catch(r){r instanceof Error&&n&&n.warning({body:r.message})}},clientScopes:w,entity:c,parameters:o}}},"$fbcQxgZ2I5"),M={class:"d-flex align-items-center justify-content-center h-100"},O={class:"oauth2-wrapper panel-card p-3 flex-column"},Q={class:"flex-column d-flex"},L={class:"text-center text-secondary"},V=t("div",null,"An external application",-1),D={class:"fs-5 fw-bold"},F={class:"mt-2 mb-2"},G={class:"ps-1 pe-1"},W={class:"flex-column"},Z=t("div",{class:"text-center",style:{width:"15px"}},[t("i",{class:"fa-solid fa-check text-success"})],-1),H={class:"ms-1"},J={class:"mt-auto"},K={class:"d-flex flex-row"},X=t("div",null,[t("i",{class:"fa-solid fa-link"})],-1),Y={class:"ms-1"},q={class:"d-flex flex-row"},ee=t("div",null,[t("i",{class:"fa fa-solid fa-lock"})],-1),te={class:"ms-1"},se={class:"ps-1 pe-1"},oe={class:"d-flex flex-row"},ie=t("div",null,[t("i",{class:"fa fa-solid fa-clock"})],-1),re={class:"ms-1"},ne={class:"d-flex justify-content-evenly mt-auto"};function ae(e,s,n,i,v,y){return h(),f("div",M,[t("div",O,[t("div",Q,[t("div",L,[V,t("div",D,a(e.entity.name),1)]),t("div",F,[t("div",null,[d(" This will allow the "),t("strong",G,a(e.entity.name),1),d(" developer to: ")]),t("div",W,[(h(!0),f(R,null,$(e.clientScopes,o=>(h(),f("div",{key:o.id,class:"d-flex flex-row"},[Z,t("div",H,[t("small",null,a(o.scope.name),1)])]))),128))])]),t("div",J,[t("div",K,[X,t("div",Y,[t("small",null,"Once authorized, you will be redirected to: "+a(e.parameters.redirect_uri),1)])]),t("div",q,[ee,t("div",te,[t("small",null,[d(" This application is governed by the "),t("strong",se,a(e.entity.name),1),d(" developer's Privacy Policy and Terms of Service. ")])])]),t("div",oe,[ie,t("div",re,[t("small",null," Active since "+a(e.entity.created_at),1)])])]),t("div",ne,[t("div",null,[t("button",{type:"button",class:"btn btn-sm btn-secondary",onClick:s[0]||(s[0]=g((...o)=>e.abort&&e.abort(...o),["prevent"]))}," Abort ")]),t("div",null,[t("button",{type:"button",class:"btn btn-sm btn-primary",onClick:s[1]||(s[1]=g((...o)=>e.authorize&&e.authorize(...o),["prevent"]))}," Authorize ")])])])])])}const _e=I(B,[["render",ae]]);export{_e as default};
