@gjermundgaraba/clankerauth-dev 0.7.2 → 0.9.0
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/README.md +5 -5
- package/dist/THIRD_PARTY_NOTICES.txt +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +38 -38
- package/dist/testing.mjs +1 -1
- package/dist/web/assets/index-Bi2toh59.js +53 -0
- package/dist/web/index.html +2 -2
- package/package.json +5 -5
- package/dist/web/assets/index-CeRYhIQg.js +0 -53
package/dist/testing.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,n as t,t as n}from"./generate_key_pair-ExJspZNk.mjs";import{randomBytes as r}from"node:crypto";import{createServer as i}from"node:http";const a=e=>typeof e==`string`,o=e=>{try{let t=JSON.parse(e);if(!(t instanceof Object)||!(`resource`in t))return;let n=t.resource;return a(n)?n:void 0}catch{return}},s=async a=>{let s=a.subject??`owner`,c=await n(`EdDSA`),l={...await t(c.publicKey),kid:`fixture`,alg:`EdDSA`,use:`sig`},u=/* @__PURE__ */ new Map,d=0,f,p=i(async(e,t)=>{let n=(e,n)=>{t.writeHead(e,{"content-type":`application/json`}),t.end(n)};if(e.url===`/api/auth/jwks`)return n(f??200,JSON.stringify({keys:[l]}));if(e.url!==`/api/issuer/verifyApiKey`||e.method!==`POST`)return n(404,`{}`);if(d++,f!==void 0)return n(f,`{}`);let r=u.get(e.headers.authorization?.replace(/^Bearer /iu,``)??``);if(r===void 0)return n(401,`{"error":"Invalid API key"}`);let i=``;for await(let t of e)i+=String(t);let a=o(i);return a===void 0?n(400,`{"error":"Invalid request"}`):a===r.resource?n(200,JSON.stringify({keyId:r.keyId,ownerId:s,resource:r.resource,scopes:r.scopes,expiresAt:null})):n(403,`{"error":"No access to this Resource"}`)});await new Promise(e=>p.listen(0,`127.0.0.1`,e));let m=p.address();if(!(m instanceof Object))throw Error(`The fake issuer failed to bind a TCP port`);let h=`http://127.0.0.1:${m.port}/api/auth`;return{issuer:h,sign:(t={},n=`at+jwt`)=>{let r=Math.floor(Date.now()/1e3);return new e({iss:h,sub:s,aud:a.resource,iat:r,exp:r+300,client_id:`fixture`,scope:a.scopes.join(` `),...t}).setProtectedHeader({alg:`EdDSA`,kid:`fixture`,typ:n}).sign(c.privateKey)},apiKey:(e,t=a.resource)=>{let n=`
|
|
1
|
+
import{i as e,n as t,t as n}from"./generate_key_pair-ExJspZNk.mjs";import{randomBytes as r}from"node:crypto";import{createServer as i}from"node:http";const a=e=>typeof e==`string`,o=e=>{try{let t=JSON.parse(e);if(!(t instanceof Object)||!(`resource`in t))return;let n=t.resource;return a(n)?n:void 0}catch{return}},s=async a=>{let s=a.subject??`owner`,c=await n(`EdDSA`),l={...await t(c.publicKey),kid:`fixture`,alg:`EdDSA`,use:`sig`},u=/* @__PURE__ */ new Map,d=0,f,p=i(async(e,t)=>{let n=(e,n)=>{t.writeHead(e,{"content-type":`application/json`}),t.end(n)};if(e.url===`/api/auth/jwks`)return n(f??200,JSON.stringify({keys:[l]}));if(e.url!==`/api/issuer/verifyApiKey`||e.method!==`POST`)return n(404,`{}`);if(d++,f!==void 0)return n(f,`{}`);let r=u.get(e.headers.authorization?.replace(/^Bearer /iu,``)??``);if(r===void 0)return n(401,`{"error":"Invalid API key"}`);let i=``;for await(let t of e)i+=String(t);let a=o(i);return a===void 0?n(400,`{"error":"Invalid request"}`):a===r.resource?n(200,JSON.stringify({keyId:r.keyId,ownerId:s,resource:r.resource,scopes:r.scopes,expiresAt:null})):n(403,`{"error":"No access to this Resource"}`)});await new Promise(e=>p.listen(0,`127.0.0.1`,e));let m=p.address();if(!(m instanceof Object))throw Error(`The fake issuer failed to bind a TCP port`);let h=`http://127.0.0.1:${m.port}/api/auth`;return{issuer:h,sign:(t={},n=`at+jwt`)=>{let r=Math.floor(Date.now()/1e3);return new e({iss:h,sub:s,aud:a.resource,iat:r,exp:r+300,client_id:`fixture`,scope:a.scopes.join(` `),...t}).setProtectedHeader({alg:`EdDSA`,kid:`fixture`,typ:n}).sign(c.privateKey)},apiKey:(e,t=a.resource)=>{let n=`clankerauth_${r(24).toString(`base64url`)}`;return u.set(n,{keyId:`key-${u.size+1}`,resource:t,scopes:e}),n},revoke:e=>{u.delete(e)},fail:e=>{f=e},verifications:()=>d,close:()=>new Promise((e,t)=>{p.closeAllConnections(),p.close(n=>n?t(n):e())})}};export{s as startFakeIssuer};
|