1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="e80a878d-77a5-42b9-afbe-3a98ab54661f",e._sentryDebugIdIdentifier="sentry-dbid-e80a878d-77a5-42b9-afbe-3a98ab54661f")}catch(e){}}(),(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2549],{37679:(e,t,s)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/sandbox/test-auth-with-popup",function(){return s(94192)}])},94192:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>j});var r=s(31085),a=s(93243),n=s.n(a),o=s(14041),c=s(40939),l=s(89643),i=s(99420),h=s.n(i),d=s(8412),p=s(33638),u=s(49823);let f=["client_id=MyOcean","response_type=code","redirect_uri=".concat(d.v.authRedirect),"scope=openid"],x="".concat(d.v.authUrl,"?").concat(f.join("&")),y="cmems-test-auth.",m=e=>{(0,u.m)({type:"error",icon:"user",msg:e})},v=e=>{(0,u.m)({type:"success",icon:"user",msg:e})},_=e=>{(0,u.m)({type:"info",icon:"user",msg:e})},g=new String("pre.jsx-108bcfb18b37c9b8{white-space:pre-wrap;word-break:break-all;font-size:.8em}.flex-column.jsx-108bcfb18b37c9b8{-webkit-box-flex:1;-webkit-flex:1 0 0px;-moz-box-flex:1;-ms-flex:1 0 0px;flex:1 0 0px}");g.__hash="108bcfb18b37c9b8";let j=()=>{let[e,t]=(0,o.useState)(null),[s,a]=(0,o.useState)(null),[i,u]=(0,o.useState)(null);(0,o.useEffect)(()=>(window.addEventListener("message",j),()=>{window.removeEventListener("message",j)}),[]),(0,o.useEffect)(()=>{w()},[]),(0,o.useEffect)(()=>{let e=setInterval(()=>{if(!(null==s?void 0:s.accessExpires))return;let e=h()(s.accessExpires).valueOf();Date.now()<e-6e4||S()},1e4);return()=>clearInterval(e)},[s]);let f=e=>e?(0,r.jsxs)("span",{"data-sentry-component":"renderExpiration","data-sentry-source-file":"test-auth-with-popup.tsx",children:[" (expires: ",h()(e).format("YYYY-MM-DD HH:mm:ss"),")"]}):null,j=e=>{let{data:t}=e;(null==t?void 0:t.type)==="authResult"&&N(t)},w=async()=>{let e=(0,p.EL)("".concat(y,"refreshToken")),t=(0,p.EL)("".concat(y,"refreshExpires"));if(console.log("Refresh token from local storage:",e,t),e&&t){if(h()(t).valueOf()<Date.now()){P();return}_("Found refresh token in localStorage"),await T(e)}},b=()=>{let e=window.open(x,"popup","popup=true,width=800,height=500");if(!e){m("Popup blocked! Please allow popups for this site.");return}
1e.focus()},k=async()=>{if(!(null==s?void 0:s.refreshToken)){_("No refresh token to log out");return}try{let e=await fetch("".concat("https://data-be-prd.marine.copernicus.eu","/api/v3/logOut"),{method:"POST",headers:{"Content-Type":"application/json","X-Auth-App":d.v.id},body:JSON.stringify({refreshToken:s.refreshToken})});if(!e.ok){let t=await e.text();throw Error("Server error: ".concat(e.status," ").concat(t))}v("Logged out successfully"),I()}catch(e){I(),m("Error logging out")}},N=e=>{_("Received ".concat(e.type," message from popup")),console.log("Received message from popup:",e.queryParams),t(e.queryParams);let{code:s}=e.queryParams;s&&E(s)},E=async e=>{try{let t=await fetch("".concat("https://data-be-prd.marine.copernicus.eu","/api/v3/logIn"),{method:"POST",headers:{"Content-Type":"application/json","X-Auth-App":d.v.id},body:JSON.stringify({code:e,redirectUri:d.v.authRedirect})});if(!t.ok){let e=await t.text();throw Error("Server error: ".concat(t.status," ").concat(e))}let s=await t.json();v("Received tokens from server"),console.log("Received tokens from server:",s),A(s)}catch(e){m("Error exchanging code for token"),console.error("Error exchanging code for token:",e),I()}},S=async()=>{(null==s?void 0:s.refreshToken)&&await T(s.refreshToken,{skipUser:!0})},T=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=t.skipUser?"".concat("https://data-be-prd.marine.copernicus.eu","/api/v3/refreshToken"):"".concat("https://data-be-prd.marine.copernicus.eu","/api/v3/logInAuto");try{let t=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","X-Auth-App":d.v.id},body:JSON.stringify({refreshToken:e})});if(!t.ok){let e=await t.text();throw Error("Server error: ".concat(t.status," ").concat(e))}let r=await t.json();v("Received refreshed tokens from server"),console.log("Received refreshed tokens from server:",r),A(r)}catch(e){m("Error refreshing tokens (maybe expired!)"),I()}},A=e=>{let{tokenInfo:t,user:s}=e;a(t),null!=s&&u(s),O(t)},I=()=>{a(null),u(null),P()},O=e=>{(0,p.qK)("".concat(y,"refreshToken"),e.refreshToken),(0,p.qK)("".concat(y,"refreshExpires"),e.refreshExpires),_("Saved refresh token to localStorage")},P=()=>{(0,p.RL)("".concat(y,"refreshToken")),(0,p.RL)("".concat(y,"refreshExpires")),_("Cleared refresh token from localStorage")},R=async()=>{try{let e=await fetch("".concat("https://data-be-prd.marine.copernicus.eu","/api/user"),{method:"GET",headers:{"X-Auth-App":d.v.id,Authorization:"Bearer ".concat(null==s?void 0:s.accessToken)}});if(!e.ok){let t=await e.text();throw Error("Server error: ".concat(e.status," ").concat(t))}let t=await e.json();v("API test successful"),console.log("API test response:",t)}catch(e){m("Error testing API"),console.error("Error testing API:",e)}};return(()=>{var t,a,o;return(0,r.jsxs)(c.s,{m:"sm",gap:"sm","data-sentry-element":"Flex","data-sentry-component":"render","data-sentry-source-file":"test-auth-with-popup.tsx",children:[(0,r.jsxs)("div",{className:"jsx-".concat(g.__hash)+" flex-column",children:[(0,r.jsx)("h1",{className:"jsx-".concat(g.__hash),children:"Auth v3 sandbox"}),(0,r.jsx)(l.$,{onClick:b,disabled:null!=i,"data-sentry-element":"Button","data-sentry-source-file":"test-auth-with-popup.tsx",children:"Log in"})," ",(0,r.jsx)(l.$,{onClick:k,disabled:null==i,"data-sentry-element":"Button","data-sentry-source-file":"test-auth-with-popup.tsx",children:"Log out"})," ",(0,r.jsx)(l.$,{onClick:S,disabled:null==i,"data-sentry-element":"Button","data-sentry-source-file":"test-auth-with-popup.tsx",children:"Refresh"})," ",(0,r.jsx)(l.$,{onClick:R,disabled:null==i,"data-sentry-element":"Button","data-sentry-source-file":"test-auth-with-popup.tsx",children:"Test API"}),(0,r.jsxs)("div",{className:"jsx-".concat(g.__hash),children:[(0,r.jsx)("h2",{className:"jsx-".concat(g.__hash),children:"User:"}),(0,r.jsx)("pre",{className:"jsx-".concat(g.__hash),children:JSON.stringify(null!=i?i:null,null,2)})]}),(0,r.jsxs)("div",{className:"jsx-".concat(g.__hash),children:[(0,r.jsx)("h2",{className:"jsx-".concat(g.__hash),children:"From popup:"}),(0,r.jsx)("pre",{className:"jsx-".concat(g.__hash),children:JSON.stringify(e,null,2)})]})]}),(0,r.jsxs)("div",{className:"jsx-".concat(g.__hash)+" flex-column",children:[(0,r.jsxs)("div",{className:"jsx-".concat(g.__hash),children:[(0,r.jsxs)("h2",{className:"jsx-".concat(g.__hash),children:["Access token",f(null==s?void 0:s.accessExpires),":"]}),(0,r.jsx)("pre",{className:"jsx-".concat(g.__hash),children:JSON.stringify(null!==(t=null==s?void 0:s.accessToken)&&void 0!==t?t:null,null,2)})]}),(0,r.jsxs)("div",{className:"jsx-".concat(g.__hash),children:[(0,r.jsxs)("h2",{className:"jsx-".concat(g.__hash),children:["Refresh token",f(null==s?void 0:s.refreshExpires),":"]}),(0,r.jsx)("pre",{className:"jsx-".concat(g.__hash),children:JSON.stringify(null!==(a=null==s?void 0:s.refreshToken)&&void 0!==a?a:null,null,2)})]}),(0,r.jsxs)("div",{className:"jsx-".concat(g.__hash),children:[(0,r.jsx)("h2",{className:"jsx-".concat(g.__hash),children:"ID token:"}),(0,r.jsx)("pre",{className:"jsx-".concat(g.__hash),children:JSON.stringify(null!==(o=null==s?void 0:s.idToken)&&void 0!==o?o:null,null,2)})]})]}),(0,r.jsx)(n(),{id:g.__hash,children:g})]})})()}},40939:(e,t,s)=>{"use strict";s.d(t,{s:()=>x});var r=s(31085),a=s(19239);s(14041);var n=s(94069),o=s(45969),c=s(89617),l=s(93837),i=s(63791),h=s(44135),d=s(21485),p=s(89094);let u={gap:{type:"spacing",property:"gap"},rowGap:{type:"spacing",property:"rowGap"},columnGap:{type:"spacing",property:"columnGap"},align:{type:"identity",property:"alignItems"},justify:{type:"identity",property:"justifyContent"},wrap:{type:"identity",property:"flexWrap"},direction:{type:"identity",property:"flexDirection"}};var f={root:"m_8bffd616"};let x=(0,p.v)((e,t)=>{let s=(0,o.Y)("Flex",null,e),{classNames:p,className:x,style:y,styles:m,unstyled:v,vars:_,gap:g,rowGap:j,columnGap:w,align:b,justify:k,wrap:N,direction:E,attributes:S,...T}=s,A=(0,c.I)({name:"Flex",classes:f,props:s,className:x,style:y,classNames:p,styles:m,unstyled:v,attributes:S,vars:_}),I=(0,n.xd)(),O=(0,h.C)(),P=(0,i.X)({styleProps:{gap:g,rowGap:j,columnGap:w,align:b,justify:k,wrap:N,direction:E},theme:I,data:u});return(0,r.jsxs)(r.Fragment,{children:[P.hasResponsiveStyles&&(0,r.jsx)(l.K,{selector:`.${O}`,styles:P.styles,media:P.media}),(0,r.jsx)(d.a,{ref:t,...A("root",{className:O,style:(0,a.J)(P.inlineStyles)}),...T})]})});x.classes=f,x.displayName="@mantine/core/Flex"}},e=>{var t=t=>e(e.s=t);e.O(0,[636,6593,8792],()=>t(37679)),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.