ec.fdk 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -7,7 +7,7 @@ ${i.verbose}`;throw new Error(c)}throw new Error(`unexpected fetch error: ${o.st
|
|
|
7
7
|
`),e(r);return}if(s===""||s==="\b"){r.length>0&&(r=r.slice(0,-1),process.stderr.write("\b \b"));continue}r+=s,process.stderr.write("*")}};n.on("data",a)})}const qn={stage:{authEndpoint:"https://login.cachena.entrecode.de/oidc/auth",tokenEndpoint:"https://login.cachena.entrecode.de/oidc/token"},live:{authEndpoint:"https://login.entrecode.de/oidc/auth",tokenEndpoint:"https://login.entrecode.de/oidc/token"}},z="ec-fdk-cli",K="http://localhost:19836/callback",On=12e4;function G(t){return t.toString("base64url")}function _n(){return G(L.randomBytes(32))}function Cn(t){return G(L.createHash("sha256").update(t).digest())}function Un(t){const e=process.platform==="darwin"?"open":process.platform==="win32"?"start":"xdg-open";me.exec(`${e} ${JSON.stringify(t)}`)}const Mn=`<!DOCTYPE html><html><body style="font-family:system-ui;display:flex;justify-content:center;align-items:center;height:100vh;margin:0">
|
|
8
8
|
<div style="text-align:center"><h1>Login successful</h1><p>You can close this tab.</p></div></body></html>`,A=t=>`<!DOCTYPE html><html><body style="font-family:system-ui;display:flex;justify-content:center;align-items:center;height:100vh;margin:0">
|
|
9
9
|
<div style="text-align:center"><h1>Login failed</h1><p>${t}</p></div></body></html>`;function Ln(t){const{authEndpoint:e,tokenEndpoint:n}=qn[t],r=_n(),a=Cn(r),o=G(L.randomBytes(16));return new Promise((s,i)=>{const c=ge.createServer(async(w,k)=>{if(!w.url?.startsWith("/callback")){k.writeHead(404),k.end();return}const T=new URL(w.url,"http://localhost").searchParams,B=T.get("code"),se=T.get("state"),_=T.get("error");if(_){k.writeHead(200,{"Content-Type":"text/html"}),k.end(A(T.get("error_description")||_)),m(),i(new Error(T.get("error_description")||_));return}if(se!==o){k.writeHead(200,{"Content-Type":"text/html"}),k.end(A("State mismatch")),m(),i(new Error("State mismatch — possible CSRF attack"));return}if(!B){k.writeHead(200,{"Content-Type":"text/html"}),k.end(A("No authorization code received")),m(),i(new Error("No authorization code received"));return}try{const D=await fetch(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",client_id:z,redirect_uri:K,code:B,code_verifier:r})});if(!D.ok){const ce=await D.text();throw new Error(`Token exchange failed: ${D.status} ${ce}`)}const N=(await D.json()).access_token;if(!N)throw new Error("No access_token in token response");k.writeHead(200,{"Content-Type":"text/html"}),k.end(Mn),m(),s(N)}catch(D){k.writeHead(200,{"Content-Type":"text/html"}),k.end(A(D.message)),m(),i(D)}}),l=setTimeout(()=>{m(),i(new Error("Login timed out after 2 minutes"))},On);function m(){clearTimeout(l),c.close()}c.listen(19836,()=>{const w=`${e}?`+new URLSearchParams({client_id:z,redirect_uri:K,response_type:"code",scope:"openid",state:o,code_challenge:a,code_challenge_method:"S256"}).toString();process.stderr.write(`Opening browser for login...
|
|
10
|
-
`),Un(w)}),c.on("error",w=>{m(),i(new Error(`Could not start local server: ${w.message}`))})})}const Rn=ue.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:document.currentScript&&document.currentScript.src||new URL("cli.cjs",document.baseURI).href),{version:Pn}=Rn("
|
|
10
|
+
`),Un(w)}),c.on("error",w=>{m(),i(new Error(`Could not start local server: ${w.message}`))})})}const Rn=ue.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:document.currentScript&&document.currentScript.src||new URL("cli.cjs",document.baseURI).href),{version:Pn}=Rn("../package.json"),Gn=`ec.fdk <command> [options]
|
|
11
11
|
|
|
12
12
|
Commands:
|
|
13
13
|
login Login via browser (OIDC). Use --password for email/password prompt.
|