import{l as g,n as b}from"./nuxt-link.a91ddf68.js";import{F as T,y as A,u as P,t as k}from"./auth.8c936e9a.js";import"./app.config.5ff5ca90.js";import{u as z}from"./entry.0b5898f4.js";import{u}from"./api.4ad3383d.js";import{r as C,h as e}from"./runtime-core.esm-bundler.24b58585.js";import"./composables.050e3231.js";import"./utils.61cc85c6.js";import"./layout.1eaf47bc.js";import"./page.16487999.js";import"./_plugin-vue_export-helper.c27b6911.js";function I(t,n){const c=Array.isArray(n)?n:[n];for(let o=0;o<c.length;o++)if(T(t,c[o]))return!0;return!1}function R(t){if(typeof t.client_id!="string"||!t.client_id||t.client_id.length===0)throw new Error("The client_id is invalid");if(typeof t.redirect_uri!="string"||!t.redirect_uri||t.redirect_uri.length===0)throw new Error("The redirect_uri is invalid");if(typeof t.response_type>"u"&&(t.response_type="code"),typeof t.response_type!="string"||t.response_type.length===0)throw new Error("The response_type is invalid");return typeof t.scope>"u"&&(t.scope=""),Array.isArray(t.scope)&&(t.scope=t.scope.join(" ")),{client_id:decodeURIComponent(t.client_id),response_type:t.response_type,redirect_uri:decodeURIComponent(t.redirect_uri),scope:decodeURIComponent(t.scope||"")}}const F=A({async setup(){const t=g(),n=P(),{loggedIn:c}=k(n);if(!c.value)return b({path:"/login",query:{...t.query,redirect:t.path}});const o=s=>e("div",{class:"d-flex align-items-center justify-content-center h-100"},[e("div",{class:"oauth2-wrapper panel-card p-3 flex-column"},[e("div",{class:"text-center"},[e("i",{class:"fa-solid fa-exclamation fa-10x text-danger"})]),e("div",{class:"text-center fs-6 p-3"},[s])])]),i=R(t.query),r=C(null);try{r.value=await u().client.getOne(i.client_id)}catch{return()=>o(["The",e("strong",{class:"ps-1 pe-1"},"client_id"),"is invalid"])}const v=(r.value.redirect_uri||"").split(",");if(!I(i.redirect_uri,v))return()=>o(["The",e("strong",{class:"ps-1 pe-1"},"redirect_uri"),"does not match."]);let l=[];typeof i.scope=="string"&&i.scope.length>0&&(l=i.scope.split(" "));const p={filter:{client_id:r.value.id},relations:["scope"]};p.filter&&l.length>0&&(p.filter.scope={name:l});const{data:m}=await u().clientScope.getMany(p),h=()=>{const s=new URL(`${i.redirect_uri}`);s.searchParams.set("error","access_denied"),s.searchParams.set("error_description","The resource owner or authorization server denied the request"),t.query.state&&typeof t.query.state=="string"&&s.searchParams.set("state",t.query.state),window.location.href=s.href},_=async()=>{try{const s=await u().post("authorize",{response_type:i.response_type,client_id:r.value.id,redirect_uri:i.redirect_uri,...t.query.state?{state:t.query.state}:{},scope:m.map(f=>f.scope.name).join(" ")}),{url:d}=s.data;window.location.href=d}catch(s){s instanceof Error&&z().warning(s.message)}},y=()=>{const s=e("div",{class:"flex-column d-flex"},[e("div",{class:"text-center text-secondary"},[e("div","An external application"),e("div",{class:"fs-5 fw-bold"},r.value.name),e("div","wants to access your account")])]);r.value.id,l.length>0;const d=m.map(a=>e("div",{class:"d-flex flex-row"},[e("div",{style:{width:"15px"},class:"text-center"},[e("i",{class:"fa-solid fa-check text-success"})]),e("div",{class:"ms-1"},[e("small",[a.scope.name])])])),f=e("div",{class:"mt-2 mb-2"},[e("div",["This will allow the",e("strong",{class:"ps-1 pe-1"},r.value.name),"developer to:"]),e("div",{class:"flex-column"},[d])]),w=e("div",{class:"mt-auto"},[e("div",{class:"d-flex flex-row"},[e("div",[e("i",{class:"fa-solid fa-link"})]),e("div",{class:"ms-1"},[e("small",["Once authorized, you will be redirected to:"," ",i.redirect_uri])])]),e("div",{class:"d-flex flex-row"},[e("div",[e("i",{class:"fa-solid fa-lock"})]),e("div",{class:"ms-1"},[e("small",["This application is governed by the",e("strong",{class:"ps-1 pe-1"},r.value.name),"developer's Privacy Policy and Terms of Service."])])]),e("div",{class:"d-flex flex-row"},[e("div",[e("i",{class:"fa-solid fa-clock"})]),e("div",{class:"ms-1"},[e("small",["Active since"," ",`${r.value.created_at}`])])])]),x=e("div",{class:"d-flex justify-content-evenly mt-auto"},[e("div",[e("button",{type:"button",class:"btn btn-sm btn-secondary",onClick:a=>(a.preventDefault(),h())},["Abort"])]),e("div",[e("button",{type:"button",class:"btn btn-sm btn-primary",onClick:a=>(a.preventDefault(),_())},["Authorize"])])]);return e("div",{class:"d-flex align-items-center justify-content-center h-100"},[e("div",{class:"oauth2-wrapper panel-card p-3 flex-column"},[s,f,w,x])])};return()=>y()}});export{F as default};
