@absolutejs/auth 0.3.1 → 0.4.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/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var Vt;(function(e){e[e.Include=0]="Include",e[e.None=1]="None"})(Vt||(Vt={}));var te;(function(e){e[e.Required=0]="Required",e[e.Ignore=1]="Ignore"})(te||(te={}));function Dt(e){return ne(e,cn,W.Include)}function J(e){return ne(e,an,W.None)}function ne(e,t,n){let i="";for(let o=0;o<e.byteLength;o+=3){let r=0,l=0;for(let u=0;u<3&&o+u<e.byteLength;u++)r=r<<8|e[o+u],l+=8;for(let u=0;u<4;u++)if(l>=6)i+=t[r>>l-6&63],l-=6;else if(l>0)i+=t[r<<6-l&63],l=0;else if(n===W.Include)i+="="}return i}var cn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",an="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";var W;(function(e){e[e.Include=0]="Include",e[e.None=1]="None"})(W||(W={}));var ee;(function(e){e[e.Required=0]="Required",e[e.Ignore=1]="Ignore"})(ee||(ee={}));class oe{uint8(e,t){if(e.byteLength<t+1)throw new TypeError("Insufficient bytes");return e[t]}uint16(e,t){if(e.byteLength<t+2)throw new TypeError("Insufficient bytes");return e[t]<<8|e[t+1]}uint32(e,t){if(e.byteLength<t+4)throw new TypeError("Insufficient bytes");let n=0;for(let i=0;i<4;i++)n|=e[t+i]<<24-i*8;return n}uint64(e,t){if(e.byteLength<t+8)throw new TypeError("Insufficient bytes");let n=0n;for(let i=0;i<8;i++)n|=BigInt(e[t+i])<<BigInt(56-i*8);return n}putUint8(e,t,n){if(e.length<n+1)throw new TypeError("Not enough space");if(t<0||t>255)throw new TypeError("Invalid uint8 value");e[n]=t}putUint16(e,t,n){if(e.length<n+2)throw new TypeError("Not enough space");if(t<0||t>65535)throw new TypeError("Invalid uint16 value");e[n]=t>>8,e[n+1]=t&255}putUint32(e,t,n){if(e.length<n+4)throw new TypeError("Not enough space");if(t<0||t>4294967295)throw new TypeError("Invalid uint32 value");for(let i=0;i<4;i++)e[n+i]=t>>(3-i)*8&255}putUint64(e,t,n){if(e.length<n+8)throw new TypeError("Not enough space");if(t<0||t>18446744073709551615n)throw new TypeError("Invalid uint64 value");for(let i=0;i<8;i++)e[n+i]=Number(t>>BigInt((7-i)*8)&0xffn)}}class se{uint8(e,t){if(e.byteLength<t+1)throw new TypeError("Insufficient bytes");return e[t]}uint16(e,t){if(e.byteLength<t+2)throw new TypeError("Insufficient bytes");return e[t]|e[t+1]<<8}uint32(e,t){if(e.byteLength<t+4)throw new TypeError("Insufficient bytes");let n=0;for(let i=0;i<4;i++)n|=e[t+i]<<i*8;return n}uint64(e,t){if(e.byteLength<t+8)throw new TypeError("Insufficient bytes");let n=0n;for(let i=0;i<8;i++)n|=BigInt(e[t+i])<<BigInt(i*8);return n}putUint8(e,t,n){if(e.length<1+n)throw new TypeError("Insufficient space");if(t<0||t>255)throw new TypeError("Invalid uint8 value");e[n]=t}putUint16(e,t,n){if(e.length<2+n)throw new TypeError("Insufficient space");if(t<0||t>65535)throw new TypeError("Invalid uint16 value");e[n+1]=t>>8,e[n]=t&255}putUint32(e,t,n){if(e.length<4+n)throw new TypeError("Insufficient space");if(t<0||t>4294967295)throw new TypeError("Invalid uint32 value");for(let i=0;i<4;i++)e[n+i]=t>>i*8&255}putUint64(e,t,n){if(e.length<8+n)throw new TypeError("Insufficient space");if(t<0||t>18446744073709551615n)throw new TypeError("Invalid uint64 value");for(let i=0;i<8;i++)e[n+i]=Number(t>>BigInt(i*8)&0xffn)}}var R=new oe,hn=new se;function p(e,t){return(e<<32-t|e>>>t)>>>0}function y(e,t){return(e<<BigInt(64-t)|e>>BigInt(t))&0xffffffffffffffffn}class re{blockSize=64;size=32;blocks=new Uint8Array(64);currentBlockSize=0;H=new Uint32Array([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);l=0n;w=new Uint32Array(64);update(e){if(this.l+=BigInt(e.byteLength)*8n,this.currentBlockSize+e.byteLength<64){this.blocks.set(e,this.currentBlockSize),this.currentBlockSize+=e.byteLength;return}let t=0;if(this.currentBlockSize>0){let n=e.slice(0,64-this.currentBlockSize);this.blocks.set(n,this.currentBlockSize),this.process(),t+=n.byteLength,this.currentBlockSize=0}while(t+64<=e.byteLength){let n=e.slice(t,t+64);this.blocks.set(n),this.process(),t+=64}if(e.byteLength-t>0){let n=e.slice(t);this.blocks.set(n),this.currentBlockSize=n.byteLength}}digest(){if(this.blocks[this.currentBlockSize]=128,this.currentBlockSize+=1,64-this.currentBlockSize<8)this.blocks.fill(0,this.currentBlockSize),this.process(),this.currentBlockSize=0;this.blocks.fill(0,this.currentBlockSize),R.putUint64(this.blocks,this.l,this.blockSize-8),this.process();let e=new Uint8Array(28);for(let t=0;t<7;t++)R.putUint32(e,this.H[t],t*4);return e}process(){for(let s=0;s<16;s++)this.w[s]=(this.blocks[s*4]<<24|this.blocks[s*4+1]<<16|this.blocks[s*4+2]<<8|this.blocks[s*4+3])>>>0;for(let s=16;s<64;s++){let f=(p(this.w[s-2],17)^p(this.w[s-2],19)^this.w[s-2]>>>10)>>>0,k=(p(this.w[s-15],7)^p(this.w[s-15],18)^this.w[s-15]>>>3)>>>0;this.w[s]=f+this.w[s-7]+k+this.w[s-16]|0}let e=this.H[0],t=this.H[1],n=this.H[2],i=this.H[3],o=this.H[4],r=this.H[5],l=this.H[6],u=this.H[7];for(let s=0;s<64;s++){let f=(p(o,6)^p(o,11)^p(o,25))>>>0,k=(o&r^~o&l)>>>0,w=u+f+k+ln[s]+this.w[s]|0,A=(p(e,2)^p(e,13)^p(e,22))>>>0,I=(e&t^e&n^t&n)>>>0,x=A+I|0;u=l,l=r,r=o,o=i+w|0,i=n,n=t,t=e,e=w+x|0}this.H[0]=e+this.H[0]|0,this.H[1]=t+this.H[1]|0,this.H[2]=n+this.H[2]|0,this.H[3]=i+this.H[3]|0,this.H[4]=o+this.H[4]|0,this.H[5]=r+this.H[5]|0,this.H[6]=l+this.H[6]|0,this.H[7]=u+this.H[7]|0}}var ln=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function $t(e){let t=new Ft;return t.update(e),t.digest()}class Ft{blockSize=64;size=32;blocks=new Uint8Array(64);currentBlockSize=0;H=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);l=0n;w=new Uint32Array(64);update(e){if(this.l+=BigInt(e.byteLength)*8n,this.currentBlockSize+e.byteLength<64){this.blocks.set(e,this.currentBlockSize),this.currentBlockSize+=e.byteLength;return}let t=0;if(this.currentBlockSize>0){let n=e.slice(0,64-this.currentBlockSize);this.blocks.set(n,this.currentBlockSize),this.process(),t+=n.byteLength,this.currentBlockSize=0}while(t+64<=e.byteLength){let n=e.slice(t,t+64);this.blocks.set(n),this.process(),t+=64}if(e.byteLength-t>0){let n=e.slice(t);this.blocks.set(n),this.currentBlockSize=n.byteLength}}digest(){if(this.blocks[this.currentBlockSize]=128,this.currentBlockSize+=1,64-this.currentBlockSize<8)this.blocks.fill(0,this.currentBlockSize),this.process(),this.currentBlockSize=0;this.blocks.fill(0,this.currentBlockSize),R.putUint64(this.blocks,this.l,this.blockSize-8),this.process();let e=new Uint8Array(32);for(let t=0;t<8;t++)R.putUint32(e,this.H[t],t*4);return e}process(){for(let s=0;s<16;s++)this.w[s]=(this.blocks[s*4]<<24|this.blocks[s*4+1]<<16|this.blocks[s*4+2]<<8|this.blocks[s*4+3])>>>0;for(let s=16;s<64;s++){let f=(p(this.w[s-2],17)^p(this.w[s-2],19)^this.w[s-2]>>>10)>>>0,k=(p(this.w[s-15],7)^p(this.w[s-15],18)^this.w[s-15]>>>3)>>>0;this.w[s]=f+this.w[s-7]+k+this.w[s-16]|0}let e=this.H[0],t=this.H[1],n=this.H[2],i=this.H[3],o=this.H[4],r=this.H[5],l=this.H[6],u=this.H[7];for(let s=0;s<64;s++){let f=(p(o,6)^p(o,11)^p(o,25))>>>0,k=(o&r^~o&l)>>>0,w=u+f+k+un[s]+this.w[s]|0,A=(p(e,2)^p(e,13)^p(e,22))>>>0,I=(e&t^e&n^t&n)>>>0,x=A+I|0;u=l,l=r,r=o,o=i+w|0,i=n,n=t,t=e,e=w+x|0}this.H[0]=e+this.H[0]|0,this.H[1]=t+this.H[1]|0,this.H[2]=n+this.H[2]|0,this.H[3]=i+this.H[3]|0,this.H[4]=o+this.H[4]|0,this.H[5]=r+this.H[5]|0,this.H[6]=l+this.H[6]|0,this.H[7]=u+this.H[7]|0}}var un=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);class L{blockSize=128;size=64;blocks=new Uint8Array(128);currentBlockSize=0;l=0n;w=new BigUint64Array(80);H;constructor(e){if(e.byteLength!==64)throw new TypeError;this.H=e}update(e){if(this.l+=BigInt(e.byteLength)*8n,this.currentBlockSize+e.byteLength<128){this.blocks.set(e,this.currentBlockSize),this.currentBlockSize+=e.byteLength;return}let t=0;if(this.currentBlockSize>0){let n=e.slice(0,128-this.currentBlockSize);this.blocks.set(n,this.currentBlockSize),this.process(),t+=n.byteLength,this.currentBlockSize=0}while(t+128<=e.byteLength){let n=e.slice(t,t+128);this.blocks.set(n),this.process(),t+=128,this.currentBlockSize=0}if(e.byteLength-t>0){let n=e.slice(t);this.blocks.set(n),this.currentBlockSize=n.byteLength}}putDigest(e){if(e.byteLength>64||e.byteLength%8!==0)throw new TypeError;if(this.blocks[this.currentBlockSize]=128,this.currentBlockSize+=1,128-this.currentBlockSize<16)this.blocks.fill(0,this.currentBlockSize),this.process(),this.currentBlockSize=0;this.blocks.fill(0,this.currentBlockSize),R.putUint64(this.blocks,this.l,this.blockSize-8),this.process();for(let t=0;t<e.byteLength/8;t++)R.putUint64(e,this.H[t],t*8)}process(){for(let s=0;s<16;s++)this.w[s]=BigInt(this.blocks[s*8])<<56n|BigInt(this.blocks[s*8+1])<<48n|BigInt(this.blocks[s*8+2])<<40n|BigInt(this.blocks[s*8+3])<<32n|BigInt(this.blocks[s*8+4])<<24n|BigInt(this.blocks[s*8+5])<<16n|BigInt(this.blocks[s*8+6])<<8n|BigInt(this.blocks[s*8+7]);for(let s=16;s<80;s++){let f=(y(this.w[s-2],19)^y(this.w[s-2],61)^this.w[s-2]>>6n)&0xffffffffffffffffn,k=(y(this.w[s-15],1)^y(this.w[s-15],8)^this.w[s-15]>>7n)&0xffffffffffffffffn;this.w[s]=f+this.w[s-7]+k+this.w[s-16]&0xffffffffffffffffn}let e=this.H[0],t=this.H[1],n=this.H[2],i=this.H[3],o=this.H[4],r=this.H[5],l=this.H[6],u=this.H[7];for(let s=0;s<80;s++){let f=(y(o,14)^y(o,18)^y(o,41))&0xffffffffffffffffn,k=(o&r^~o&l)&0xffffffffffffffffn,w=u+f+k+fn[s]+this.w[s]&0xffffffffffffffffn,A=(y(e,28)^y(e,34)^y(e,39))&0xffffffffffffffffn,I=(e&t^e&n^t&n)&0xffffffffffffffffn,x=A+I&0xffffffffffffffffn;u=l,l=r,r=o,o=i+w&0xffffffffffffffffn,i=n,n=t,t=e,e=w+x&0xffffffffffffffffn}this.H[0]=e+this.H[0]&0xffffffffffffffffn,this.H[1]=t+this.H[1]&0xffffffffffffffffn,this.H[2]=n+this.H[2]&0xffffffffffffffffn,this.H[3]=i+this.H[3]&0xffffffffffffffffn,this.H[4]=o+this.H[4]&0xffffffffffffffffn,this.H[5]=r+this.H[5]&0xffffffffffffffffn,this.H[6]=l+this.H[6]&0xffffffffffffffffn,this.H[7]=u+this.H[7]&0xffffffffffffffffn}}class ce{blockSize=128;size=64;sha512=new L(new BigUint64Array([0x6a09e667f3bcc908n,0xbb67ae8584caa73bn,0x3c6ef372fe94f82bn,0xa54ff53a5f1d36f1n,0x510e527fade682d1n,0x9b05688c2b3e6c1fn,0x1f83d9abfb41bd6bn,0x5be0cd19137e2179n]));update(e){this.sha512.update(e)}digest(){let e=new Uint8Array(64);return this.sha512.putDigest(e),e}}var fn=new BigUint64Array([0x428a2f98d728ae22n,0x7137449123ef65cdn,0xb5c0fbcfec4d3b2fn,0xe9b5dba58189dbbcn,0x3956c25bf348b538n,0x59f111f1b605d019n,0x923f82a4af194f9bn,0xab1c5ed5da6d8118n,0xd807aa98a3030242n,0x12835b0145706fben,0x243185be4ee4b28cn,0x550c7dc3d5ffb4e2n,0x72be5d74f27b896fn,0x80deb1fe3b1696b1n,0x9bdc06a725c71235n,0xc19bf174cf692694n,0xe49b69c19ef14ad2n,0xefbe4786384f25e3n,0x0fc19dc68b8cd5b5n,0x240ca1cc77ac9c65n,0x2de92c6f592b0275n,0x4a7484aa6ea6e483n,0x5cb0a9dcbd41fbd4n,0x76f988da831153b5n,0x983e5152ee66dfabn,0xa831c66d2db43210n,0xb00327c898fb213fn,0xbf597fc7beef0ee4n,0xc6e00bf33da88fc2n,0xd5a79147930aa725n,0x06ca6351e003826fn,0x142929670a0e6e70n,0x27b70a8546d22ffcn,0x2e1b21385c26c926n,0x4d2c6dfc5ac42aedn,0x53380d139d95b3dfn,0x650a73548baf63den,0x766a0abb3c77b2a8n,0x81c2c92e47edaee6n,0x92722c851482353bn,0xa2bfe8a14cf10364n,0xa81a664bbc423001n,0xc24b8b70d0f89791n,0xc76c51a30654be30n,0xd192e819d6ef5218n,0xd69906245565a910n,0xf40e35855771202an,0x106aa07032bbd1b8n,0x19a4c116b8d2d0c8n,0x1e376c085141ab53n,0x2748774cdf8eeb99n,0x34b0bcb5e19b48a8n,0x391c0cb3c5c95a63n,0x4ed8aa4ae3418acbn,0x5b9cca4f7763e373n,0x682e6ff3d6b2b8a3n,0x748f82ee5defb2fcn,0x78a5636f43172f60n,0x84c87814a1f0ab72n,0x8cc702081a6439ecn,0x90befffa23631e28n,0xa4506cebde82bde9n,0xbef9a3f7b2c67915n,0xc67178f2e372532bn,0xca273eceea26619cn,0xd186b8c721c0c207n,0xeada7dd6cde0eb1en,0xf57d4f7fee6ed178n,0x06f067aa72176fban,0x0a637dc5a2c898a6n,0x113f9804bef90daen,0x1b710b35131c471bn,0x28db77f523047d84n,0x32caab7b40c72493n,0x3c9ebe0a15c9bebcn,0x431d67c49c100d4cn,0x4cc5d4becb3e42b6n,0x597f299cfc657e2an,0x5fcb6fab3ad6faecn,0x6c44198c4a475817n]);class ae{blockSize=128;size=48;sha512=new L(new BigUint64Array([0xcbbb9d5dc1059ed8n,0x629a292a367cd507n,0x9159015a3070dd17n,0x152fecd8f70e5939n,0x67332667ffc00b31n,0x8eb44a8768581511n,0xdb0c2e0d64f98fa7n,0x47b5481dbefa4fa4n]));update(e){this.sha512.update(e)}digest(){let e=new Uint8Array(48);return this.sha512.putDigest(e),e}}class he{blockSize=128;size=28;sha512=new L(new BigUint64Array([0x8c3d37c819544da2n,0x73e1996689dcd4d6n,0x1dfab7ae32ff9c82n,0x679dd514582f9fcfn,0x0f6d2b697bd44da8n,0x77e36f7304c48942n,0x3f9d85a86a1d36c8n,0x1112e6ad91d692a1n]));update(e){this.sha512.update(e)}digest(){let e=new Uint8Array(32);return this.sha512.putDigest(e),e.slice(0,28)}}class le{blockSize=128;size=28;sha512=new L(new BigUint64Array([0x22312194fc2bf72cn,0x9f555fa3c84c64c2n,0x2393b86b6f53b151n,0x963877195940eabdn,0x96283ee2a88effe3n,0xbe5e1e2553863992n,0x2b0199fc2c85b8aan,0x0eb72ddc81c52ca2n]));update(e){this.sha512.update(e)}digest(){let e=new Uint8Array(32);return this.sha512.putDigest(e),e}}class N{data;constructor(e){this.data=e}tokenType(){if("token_type"in this.data&&typeof this.data.token_type==="string")return this.data.token_type;throw new Error("Missing or invalid 'token_type' field")}accessToken(){if("access_token"in this.data&&typeof this.data.access_token==="string")return this.data.access_token;throw new Error("Missing or invalid 'access_token' field")}accessTokenExpiresInSeconds(){if("expires_in"in this.data&&typeof this.data.expires_in==="number")return this.data.expires_in;throw new Error("Missing or invalid 'expires_in' field")}accessTokenExpiresAt(){return new Date(Date.now()+this.accessTokenExpiresInSeconds()*1000)}hasRefreshToken(){return"refresh_token"in this.data&&typeof this.data.refresh_token==="string"}refreshToken(){if("refresh_token"in this.data&&typeof this.data.refresh_token==="string")return this.data.refresh_token;throw new Error("Missing or invalid 'refresh_token' field")}hasScopes(){return"scope"in this.data&&typeof this.data.scope==="string"}scopes(){if("scope"in this.data&&typeof this.data.scope==="string")return this.data.scope.split(" ");throw new Error("Missing or invalid 'scope' field")}idToken(){if("id_token"in this.data&&typeof this.data.id_token==="string")return this.data.id_token;throw new Error("Missing or invalid field 'id_token'")}}function z(e){let t=$t(new TextEncoder().encode(e));return J(t)}function Xt(){let e=new Uint8Array(32);return crypto.getRandomValues(e),J(e)}function Yt(){let e=new Uint8Array(32);return crypto.getRandomValues(e),J(e)}function ue(e,t){if(t.length!==1)throw new TypeError("Invalid character string");let n=0;while(n<e.length&&e[n]===t)n++;return e.slice(n)}function Qt(e,t){if(t.length!==1)throw new TypeError("Invalid character string");let n=e.length;while(n>0&&e[n-1]===t)n--;return e.slice(0,n)}function m(e,...t){let n=Qt(e,"/");for(let i of t)n=Qt(n,"/")+"/"+ue(i,"/");return n}function c(e,t){let n=new TextEncoder().encode(t.toString()),i=new Request(e,{method:"POST",body:n});return i.headers.set("Content-Type","application/x-www-form-urlencoded"),i.headers.set("Accept","application/json"),i.headers.set("User-Agent","arctic"),i.headers.set("Content-Length",n.byteLength.toString()),i}function U(e,t){let n=new TextEncoder().encode(`${e}:${t}`);return Dt(n)}async function a(e){let t;try{t=await fetch(e)}catch(n){throw new T(n)}if(t.status===400||t.status===401){let n;try{n=await t.json()}catch{throw new _(t.status)}if(typeof n!=="object"||n===null)throw new b(t.status,n);let i;try{i=X(n)}catch{throw new b(t.status,n)}throw i}if(t.status===200){let n;try{n=await t.json()}catch{throw new _(t.status)}if(typeof n!=="object"||n===null)throw new b(t.status,n);return new N(n)}if(t.body!==null)await t.body.cancel();throw new _(t.status)}async function S(e){let t;try{t=await fetch(e)}catch(n){throw new T(n)}if(t.status===400||t.status===401){let n;try{n=await t.json()}catch{throw new b(t.status,null)}if(typeof n!=="object"||n===null)throw new b(t.status,n);let i;try{i=X(n)}catch{throw new b(t.status,n)}throw i}if(t.status===200){if(t.body!==null)await t.body.cancel();return}if(t.body!==null)await t.body.cancel();throw new _(t.status)}function X(e){let t;if("error"in e&&typeof e.error==="string")t=e.error;else throw new Error("Invalid error response");let n=null,i=null,o=null;if("error_description"in e){if(typeof e.error_description!=="string")throw new Error("Invalid data");n=e.error_description}if("error_uri"in e){if(typeof e.error_uri!=="string")throw new Error("Invalid data");i=e.error_uri}if("state"in e){if(typeof e.state!=="string")throw new Error("Invalid data");o=e.state}return new K(t,n,i,o)}class T extends Error{constructor(e){super("Failed to send request",{cause:e})}}class K extends Error{code;description;uri;state;constructor(e,t,n,i){super(`OAuth request error: ${e}`);this.code=e,this.description=t,this.uri=n,this.state=i}}class _ extends Error{status;constructor(e){super("Unexpected error response");this.status=e}}class b extends Error{status;data;constructor(e,t){super("Unexpected error response body");this.status=e,this.data=t}}class h{clientId;clientPassword;redirectURI;constructor(e,t,n){this.clientId=e,this.clientPassword=t,this.redirectURI=n}createAuthorizationURL(e,t,n){let i=new URL(e);if(i.searchParams.set("response_type","code"),i.searchParams.set("client_id",this.clientId),this.redirectURI!==null)i.searchParams.set("redirect_uri",this.redirectURI);if(i.searchParams.set("state",t),n.length>0)i.searchParams.set("scope",n.join(" "));return i}createAuthorizationURLWithPKCE(e,t,n,i,o){let r=new URL(e);if(r.searchParams.set("response_type","code"),r.searchParams.set("client_id",this.clientId),this.redirectURI!==null)r.searchParams.set("redirect_uri",this.redirectURI);if(r.searchParams.set("state",t),n===d.S256){let l=z(i);r.searchParams.set("code_challenge_method","S256"),r.searchParams.set("code_challenge",l)}else if(n===d.Plain)r.searchParams.set("code_challenge_method","plain"),r.searchParams.set("code_challenge",i);if(o.length>0)r.searchParams.set("scope",o.join(" "));return r}async validateAuthorizationCode(e,t,n){let i=new URLSearchParams;if(i.set("grant_type","authorization_code"),i.set("code",t),this.redirectURI!==null)i.set("redirect_uri",this.redirectURI);if(n!==null)i.set("code_verifier",n);if(this.clientPassword===null)i.set("client_id",this.clientId);let o=c(e,i);if(this.clientPassword!==null){let l=U(this.clientId,this.clientPassword);o.headers.set("Authorization",`Basic ${l}`)}return await a(o)}async refreshAccessToken(e,t,n){let i=new URLSearchParams;if(i.set("grant_type","refresh_token"),i.set("refresh_token",t),this.clientPassword===null)i.set("client_id",this.clientId);if(n.length>0)i.set("scope",n.join(" "));let o=c(e,i);if(this.clientPassword!==null){let l=U(this.clientId,this.clientPassword);o.headers.set("Authorization",`Basic ${l}`)}return await a(o)}async revokeToken(e,t){let n=new URLSearchParams;if(n.set("token",t),this.clientPassword===null)n.set("client_id",this.clientId);let i=c(e,n);if(this.clientPassword!==null){let o=U(this.clientId,this.clientPassword);i.headers.set("Authorization",`Basic ${o}`)}await S(i)}}var d;(function(e){e[e.S256=0]="S256",e[e.Plain=1]="Plain"})(d||(d={}));class Y{authorizationEndpoint;tokenEndpoint;tokenRevocationEndpoint;client;constructor(e,t,n,i){this.authorizationEndpoint=`https://${e}/oauth2/authorize`,this.tokenEndpoint=`https://${e}/oauth2/token`,this.tokenRevocationEndpoint=`https://${e}/oauth2/revoke`,this.client=new h(t,n,i)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,t)}async refreshAccessToken(e,t){return await this.client.refreshAccessToken(this.tokenEndpoint,e,t)}async revokeToken(e){await this.client.revokeToken(this.tokenRevocationEndpoint,e)}}var pn="https://anilist.co/api/v2/oauth/authorize",kn="https://anilist.co/api/v2/oauth/token";class Q{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e){return this.client.createAuthorizationURL(pn,e,[])}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(kn,e,null)}}var fe;(function(e){e[e.Include=0]="Include",e[e.None=1]="None"})(fe||(fe={}));var de;(function(e){e[e.Required=0]="Required",e[e.Ignore=1]="Ignore"})(de||(de={}));function P(e){return wn(e,mn,Z.None)}function wn(e,t,n){let i="";for(let o=0;o<e.byteLength;o+=3){let r=0,l=0;for(let u=0;u<3&&o+u<e.byteLength;u++)r=r<<8|e[o+u],l+=8;for(let u=0;u<4;u++)if(l>=6)i+=t[r>>l-6&63],l-=6;else if(l>0)i+=t[r<<6-l&63],l=0;else if(n===Z.Include)i+="="}return i}var mn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";function Zt(e){return xn(e,gn,j.Ignore)}function xn(e,t,n){let i=new Uint8Array(Math.ceil(e.length/4)*3),o=0;for(let r=0;r<e.length;r+=4){let l=0,u=0;for(let f=0;f<4;f++){if(n===j.Required&&e[r+f]==="=")continue;if(n===j.Ignore&&(r+f>=e.length||e[r+f]==="="))continue;if(f>0&&e[r+f-1]==="=")throw new Error("Invalid padding");if(!(e[r+f]in t))throw new Error("Invalid character");l|=t[e[r+f]]<<(3-f)*6,u+=6}if(u<24){let f;if(u===12)f=l&65535;else if(u===18)f=l&255;else throw new Error("Invalid padding");if(f!==0)throw new Error("Invalid padding")}let s=Math.floor(u/8);for(let f=0;f<s;f++)i[o]=l>>16-f*8&255,o++}return i.slice(0,o)}var Z;(function(e){e[e.Include=0]="Include",e[e.None=1]="None"})(Z||(Z={}));var j;(function(e){e[e.Required=0]="Required",e[e.Ignore=1]="Ignore"})(j||(j={}));var gn={"0":52,"1":53,"2":54,"3":55,"4":56,"5":57,"6":58,"7":59,"8":60,"9":61,A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25,a:26,b:27,c:28,d:29,e:30,f:31,g:32,h:33,i:34,j:35,k:36,l:37,m:38,n:39,o:40,p:41,q:42,r:43,s:44,t:45,u:46,v:47,w:48,x:49,y:50,z:51,"-":62,_:63};function pe(e){let t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT");let n;try{n=new TextDecoder().decode(Zt(t[1]))}catch{throw new Error("Invalid JWT: Invalid base64url encoding")}let i;try{i=JSON.parse(n)}catch{throw new Error("Invalid JWT: Invalid JSON encoding")}if(typeof i!=="object"||i===null)throw new Error("Invalid JWT: Invalid payload");return i}function ke(e,t,n){let i=P(new TextEncoder().encode(e)),o=P(new TextEncoder().encode(t)),r=P(n);return i+"."+o+"."+r}function we(e,t){let n=P(new TextEncoder().encode(e)),i=P(new TextEncoder().encode(t)),o=n+"."+i;return new TextEncoder().encode(o)}var An="https://appleid.apple.com/auth/authorize",zn="https://appleid.apple.com/auth/token";class G{clientId;teamId;keyId;pkcs8PrivateKey;redirectURI;constructor(e,t,n,i,o){this.clientId=e,this.teamId=t,this.keyId=n,this.pkcs8PrivateKey=i,this.redirectURI=o}createAuthorizationURL(e,t){let n=new URL(An);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId);let n=await this.createClientSecret();t.set("client_secret",n);let i=c(zn,t);return await a(i)}async createClientSecret(){let e=await crypto.subtle.importKey("pkcs8",this.pkcs8PrivateKey,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]),t=Math.floor(Date.now()/1000),n=JSON.stringify({typ:"JWT",alg:"ES256",kid:this.keyId}),i=JSON.stringify({iss:this.teamId,exp:t+300,aud:["https://appleid.apple.com"],sub:this.clientId,iat:t}),o=new Uint8Array(await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,we(n,i)));return ke(n,i,o)}}var yn="https://auth.atlassian.com/authorize",xe="https://auth.atlassian.com/oauth/token";class V{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(yn);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n.searchParams.set("audience","api.atlassian.com"),n.searchParams.set("prompt","consent"),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(xe,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(xe,t);return await a(n)}}class tt{authorizationEndpoint;tokenEndpoint;tokenRevocationEndpoint;client;constructor(e,t,n,i){this.authorizationEndpoint=`https://${e}/authorize`,this.tokenEndpoint=`https://${e}/oauth/token`,this.tokenRevocationEndpoint=`https://${e}/oauth/revoke`,this.client=new h(t,n,i)}createAuthorizationURL(e,t,n){let i;if(t!==null)i=this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,d.S256,t,n);else i=this.client.createAuthorizationURL(this.authorizationEndpoint,e,n);return i}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(this.tokenEndpoint,e,[])}async revokeToken(e){await this.client.revokeToken(this.tokenRevocationEndpoint,e)}}class et{authorizationEndpoint;tokenEndpoint;tokenRevocationEndpoint;client;constructor(e,t,n,i){this.authorizationEndpoint=m(e,"/application/o/authorize/"),this.tokenEndpoint=m(e,"/application/o/token/"),this.tokenRevocationEndpoint=m(e,"/application/o/revoke/"),this.client=new h(t,n,i)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(this.tokenEndpoint,e,[])}async revokeToken(e){await this.client.revokeToken(this.tokenRevocationEndpoint,e)}}var bn="https://bitbucket.org/site/oauth2/authorize",ge="https://bitbucket.org/site/oauth2/access_token";class nt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e){return this.client.createAuthorizationURL(bn,e,[])}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(ge,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken(ge,e,[])}}var Rn="https://account.box.com/api/oauth2/authorize",Ie="https://api.box.com/oauth2/token",Un="https://api.box.com/oauth2/revoke";class it{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(Rn);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ie,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ie,t);return await a(n)}async revokeToken(e){let t=new URLSearchParams;t.set("token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Un,t);await S(n)}}var En="https://www.coinbase.com/oauth/authorize",Ae="https://www.coinbase.com/oauth/token",_n="https://api.coinbase.com/oauth/revoke";class ot{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(En);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ae,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ae,t);return await a(n)}async revokeToken(e){let t=new URLSearchParams;t.set("token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(_n,t);await S(n)}}var ze="https://discord.com/oauth2/authorize",ye="https://discord.com/api/oauth2/token",Sn="https://discord.com/api/oauth2/token/revoke";class st{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t,n){let i;if(t!==null)i=this.client.createAuthorizationURLWithPKCE(ze,e,d.S256,t,n);else i=this.client.createAuthorizationURL(ze,e,n);return i}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(ye,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(ye,e,[])}async revokeToken(e){await this.client.revokeToken(Sn,e)}}var vn="https://dribbble.com/oauth/authorize",Ln="https://dribbble.com/oauth/token";class rt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(vn);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ln,t);return await a(n)}}var Tn="https://www.dropbox.com/oauth2/authorize",be="https://api.dropboxapi.com/oauth2/token",Cn="https://api.dropboxapi.com/2/auth/token/revoke";class ct{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(Tn,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(be,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken(be,e,[])}async revokeToken(e){await this.client.revokeToken(Cn,e)}}var Pn="https://www.facebook.com/v16.0/dialog/oauth",Bn="https://graph.facebook.com/v16.0/oauth/access_token";class at{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(Pn);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Bn,t);return await a(n)}}var Hn="https://www.figma.com/oauth",Nn="https://api.figma.com/v1/oauth/token",On="https://api.figma.com/v1/oauth/refresh";class ht{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(Hn,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(Nn,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken(On,e,[])}}var qn="https://github.com/login/oauth/authorize",Re="https://github.com/login/oauth/access_token";class lt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(qn);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));if(this.redirectURI!==null)n.searchParams.set("redirect_uri",this.redirectURI);return n}async validateAuthorizationCode(e){let t=new URLSearchParams;if(t.set("grant_type","authorization_code"),t.set("code",e),this.redirectURI!==null)t.set("redirect_uri",this.redirectURI);let n=c(Re,t),i=U(this.clientId,this.clientSecret);return n.headers.set("Authorization",`Basic ${i}`),await Ue(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e);let n=c(Re,t),i=U(this.clientId,this.clientSecret);return n.headers.set("Authorization",`Basic ${i}`),await Ue(n)}}async function Ue(e){let t;try{t=await fetch(e)}catch(o){throw new T(o)}if(t.status!==200){if(t.body!==null)await t.body.cancel();throw new _(t.status)}let n;try{n=await t.json()}catch{throw new _(t.status)}if(typeof n!=="object"||n===null)throw new b(t.status,n);if("error"in n&&typeof n.error==="string"){let o;try{o=X(n)}catch{throw new b(t.status,n)}throw o}return new N(n)}class ut{authorizationEndpoint;tokenEndpoint;tokenRevocationEndpoint;client;constructor(e,t,n,i){this.authorizationEndpoint=m(e,"/oauth/authorize"),this.tokenEndpoint=m(e,"/oauth/token"),this.tokenRevocationEndpoint=m(e,"/oauth/revoke"),this.client=new h(t,n,i)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(this.authorizationEndpoint,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken(this.tokenEndpoint,e,[])}async revokeToken(e){await this.client.revokeToken(this.tokenRevocationEndpoint,e)}}var Mn="https://accounts.google.com/o/oauth2/v2/auth",Ee="https://oauth2.googleapis.com/token",Wn="https://oauth2.googleapis.com/revoke";class ft{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(Mn,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(Ee,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(Ee,e,[])}async revokeToken(e){await this.client.revokeToken(Wn,e)}}var Jn="https://appcenter.intuit.com/connect/oauth2",_e="https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer",Kn="https://developer.API.intuit.com/v2/oauth2/tokens/revoke";class dt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(Jn,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(_e,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken(_e,e,[])}async revokeToken(e){await this.client.revokeToken(Kn,e)}}var jn="https://kauth.kakao.com/oauth/authorize",Se="https://kauth.kakao.com/oauth/token";class pt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(jn);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Se,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Se,t);return await a(n)}}class kt{authorizationEndpoint;tokenEndpoint;tokenRevocationEndpoint;client;constructor(e,t,n,i){this.authorizationEndpoint=e+"/protocol/openid-connect/auth",this.tokenEndpoint=e+"/protocol/openid-connect/token",this.tokenRevocationEndpoint=e+"/protocol/openid-connect/revoke",this.client=new h(t,n,i)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(this.tokenEndpoint,e,[])}async revokeToken(e){await this.client.revokeToken(this.tokenRevocationEndpoint,e)}}var Dn="https://lichess.org/oauth",$n="https://lichess.org/api/token";class wt{client;constructor(e,t){this.client=new h(e,null,t)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(Dn,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode($n,e,t)}}var Fn="https://access.line.me/oauth2/v2.1/authorize",ve="https://api.line.me/oauth2/v2.1/token";class mt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t,n){let i=new URL(Fn);if(i.searchParams.set("response_type","code"),i.searchParams.set("client_id",this.clientId),i.searchParams.set("state",e),n.length>0)i.searchParams.set("scope",n.join(" "));i.searchParams.set("redirect_uri",this.redirectURI);let o=z(t);return i.searchParams.set("code_challenge_method","S256"),i.searchParams.set("code_challenge",o),i}async validateAuthorizationCode(e,t){let n=new URLSearchParams;n.set("grant_type","authorization_code"),n.set("code",e),n.set("code_verifier",t),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId),n.set("client_secret",this.clientSecret);let i=c(ve,n);return await a(i)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(ve,t);return await a(n)}}var Xn="https://linear.app/oauth/authorize",Yn="https://api.linear.app/oauth/token";class xt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(Xn);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Yn,t);return await a(n)}}var Qn="https://www.linkedin.com/oauth/v2/authorization",Le="https://www.linkedin.com/oauth/v2/accessToken";class gt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(Qn);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Le,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Le,t);return await a(n)}}class It{authorizationEndpoint;tokenEndpoint;clientId;clientSecret;redirectURI;constructor(e,t,n,i){this.authorizationEndpoint=m("https://login.microsoftonline.com",e,"/oauth2/v2.0/authorize"),this.tokenEndpoint=m("https://login.microsoftonline.com",e,"/oauth2/v2.0/token"),this.clientId=t,this.clientSecret=n,this.redirectURI=i}createAuthorizationURL(e,t,n){let i=new URL(this.authorizationEndpoint);i.searchParams.set("response_type","code"),i.searchParams.set("client_id",this.clientId),i.searchParams.set("redirect_uri",this.redirectURI),i.searchParams.set("state",e);let o=z(t);if(i.searchParams.set("code_challenge_method","S256"),i.searchParams.set("code_challenge",o),n.length>0)i.searchParams.set("scope",n.join(" "));return i}async validateAuthorizationCode(e,t){let n=new URLSearchParams;if(n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("code_verifier",t),this.clientSecret===null)n.set("client_id",this.clientId);let i=c(this.tokenEndpoint,n);if(this.clientSecret!==null){let r=U(this.clientId,this.clientSecret);i.headers.set("Authorization",`Basic ${r}`)}else i.headers.set("Origin","arctic");return await a(i)}async refreshAccessToken(e,t){let n=new URLSearchParams;if(n.set("grant_type","refresh_token"),n.set("refresh_token",e),this.clientSecret===null)n.set("client_id",this.clientId);if(t.length>0)n.set("scope",t.join(" "));let i=c(this.tokenEndpoint,n);if(this.clientSecret!==null){let r=U(this.clientId,this.clientSecret);i.headers.set("Authorization",`Basic ${r}`)}else i.headers.set("Origin","arctic");return await a(i)}}var Zn="https://myanimelist.net/v1/oauth2/authorize",Te="https://myanimelist.net/v1/oauth2/token";class At{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURLWithPKCE(Zn,e,d.Plain,t,[])}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(Te,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(Te,e,[])}}var Gn="https://api.notion.com/v1/oauth/authorize",Vn="https://api.notion.com/v1/oauth/token";class zt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e){let t=this.client.createAuthorizationURL(Gn,e,[]);return t.searchParams.set("owner","user"),t}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(Vn,e,null)}}class yt{authorizationEndpoint;tokenEndpoint;tokenRevocationEndpoint;client;constructor(e,t,n,i,o){let r=`https://${e}/oauth2`;if(t!==null)r=m(r,t);this.authorizationEndpoint=m(r,"/v1/authorize"),this.tokenEndpoint=m(r,"/v1/token"),this.tokenRevocationEndpoint=m(r,"/v1/revoke"),this.client=new h(n,i,o)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,t)}async refreshAccessToken(e,t){return await this.client.refreshAccessToken(this.tokenEndpoint,e,t)}async revokeToken(e){await this.client.revokeToken(this.tokenRevocationEndpoint,e)}}var ti="https://osu.ppy.sh/oauth/authorize",Ce="https://osu.ppy.sh/oauth/token";class bt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(ti);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));if(this.redirectURI!==null)n.searchParams.set("redirect_uri",this.redirectURI);return n}async validateAuthorizationCode(e){let t=new URLSearchParams;if(t.set("grant_type","authorization_code"),t.set("code",e),this.redirectURI!==null)t.set("redirect_uri",this.redirectURI);t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ce,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ce,t);return await a(n)}}var ei="https://www.patreon.com/oauth2/authorize",Pe="https://www.patreon.com/api/oauth2/token";class Rt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(ei);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Pe,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Pe,t);return await a(n)}}var ni="https://www.reddit.com/api/v1/authorize",Be="https://www.reddit.com/api/v1/access_token";class Ut{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(ni,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(Be,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken(Be,e,[])}}var ii="https://apis.roblox.com/oauth/v1/authorize",He="https://apis.roblox.com/oauth/v1/token",oi="https://apis.roblox.com/oauth/v1/token/revoke";class Et{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(ii,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(He,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(He,e,[])}async revokeToken(e){await this.client.revokeToken(oi,e)}}class _t{authorizationEndpoint;tokenEndpoint;tokenRevocationEndpoint;client;constructor(e,t,n,i){this.authorizationEndpoint=`https://${e}/services/oauth2/authorize`,this.tokenEndpoint=`https://${e}/services/oauth2/token`,this.tokenRevocationEndpoint=`https://${e}/services/oauth2/revoke`,this.client=new h(t,n,i)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(this.authorizationEndpoint,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(this.tokenEndpoint,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(this.tokenEndpoint,e,[])}async revokeToken(e){await this.client.revokeToken(this.tokenRevocationEndpoint,e)}}var si="https://shikimori.one/oauth/authorize",Ne="https://shikimori.one/oauth/token";class St{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e){let t=new URL(si);return t.searchParams.set("response_type","code"),t.searchParams.set("client_id",this.clientId),t.searchParams.set("state",e),t.searchParams.set("redirect_uri",this.redirectURI),t}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ne,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ne,t);return await a(n)}}var ri="https://slack.com/openid/connect/authorize",ci="https://slack.com/api/openid.connect.token";class vt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(ri,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(ci,e,null)}}var Oe="https://accounts.spotify.com/authorize",qe="https://accounts.spotify.com/api/token";class Lt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t,n){let i;if(t!==null)i=this.client.createAuthorizationURLWithPKCE(Oe,e,d.S256,t,n);else i=this.client.createAuthorizationURL(Oe,e,n);return i}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(qe,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(qe,e,[])}}var ai="https://www.strava.com/oauth/authorize",Me="https://www.strava.com/api/v3/oauth/token";class Tt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(ai);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(","));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Me,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Me,t);return await a(n)}}var hi="https://v5api.tiltify.com/oauth/authorizeze",We="https://v5api.tiltify.com/oauth/token";class Ct{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(hi);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(We,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(We,t);return await a(n)}}var li="https://www.tumblr.com/oauth2/authorize",Je="https://api.tumblr.com/v2/oauth2/token";class Pt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(li,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(Je,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken(Je,e,[])}}var ui="https://id.twitch.tv/oauth2/authorize",Ke="https://id.twitch.tv/oauth2/token";class Bt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(ui);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ke,t);return await a(n)}async refreshAccessToken(e){let t=new URLSearchParams;t.set("grant_type","refresh_token"),t.set("refresh_token",e),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(Ke,t);return await a(n)}}var fi="https://twitter.com/i/oauth2/authorize",je="https://api.twitter.com/2/oauth2/token",di="https://api.twitter.com/2/oauth2/revoke";class Ht{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(fi,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(je,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(je,e,[])}async revokeToken(e){await this.client.revokeToken(di,e)}}var pi="https://oauth.vk.com/authorize",ki="https://oauth.vk.com/access_token";class Nt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(pi);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(ki,t);return await a(n)}}var wi="https://api.workos.com/sso/authorize",mi="https://api.workos.com/sso/token";class Ot{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(wi);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),n.searchParams.set("redirect_uri",this.redirectURI),t!==null){let i=z(t);n.searchParams.set("code_challenge_method","S256"),n.searchParams.set("code_challenge",i)}return n}async validateAuthorizationCode(e,t){let n=new URLSearchParams;if(n.set("grant_type","authorization_code"),n.set("code",e),n.set("redirect_uri",this.redirectURI),n.set("client_id",this.clientId),this.clientSecret!==null)n.set("client_secret",this.clientSecret);if(t!==null)n.set("code_verifier",t);let i=c(mi,n);return await a(i)}}var xi="https://api.login.yahoo.com/oauth2/request_auth",De="https://api.login.yahoo.com/oauth2/get_token";class qt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(xi,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode(De,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken(De,e,[])}}var gi="https://oauth.yandex.com/authorize",$e="https://oauth.yandex.com/token";class Mt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t){return this.client.createAuthorizationURL(gi,e,t)}async validateAuthorizationCode(e){return await this.client.validateAuthorizationCode($e,e,null)}async refreshAccessToken(e){return await this.client.refreshAccessToken($e,e,[])}}var Ii="https://zoom.us/oauth/authorize",Fe="https://zoom.us/oauth/token",Ai="https://zoom.us/oauth/revoke";class Wt{client;constructor(e,t,n){this.client=new h(e,t,n)}createAuthorizationURL(e,t,n){return this.client.createAuthorizationURLWithPKCE(Ii,e,d.S256,t,n)}async validateAuthorizationCode(e,t){return await this.client.validateAuthorizationCode(Fe,e,t)}async refreshAccessToken(e){return await this.client.refreshAccessToken(Fe,e,[])}async revokeToken(e){await this.client.revokeToken(Ai,e)}}var zi="https://api.intra.42.fr/oauth/authorize",yi="https://api.intra.42.fr/oauth/token";class Jt{clientId;clientSecret;redirectURI;constructor(e,t,n){this.clientId=e,this.clientSecret=t,this.redirectURI=n}createAuthorizationURL(e,t){let n=new URL(zi);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",this.clientId),n.searchParams.set("state",e),t.length>0)n.searchParams.set("scope",t.join(" "));return n.searchParams.set("redirect_uri",this.redirectURI),n}async validateAuthorizationCode(e){let t=new URLSearchParams;t.set("grant_type","authorization_code"),t.set("code",e),t.set("redirect_uri",this.redirectURI),t.set("client_id",this.clientId),t.set("client_secret",this.clientSecret);let n=c(yi,t);return await a(n)}}function Gt(e){try{return pe(e)}catch(t){throw new Error("Invalid ID token",{cause:t})}}import{Elysia as Ti}from"elysia";import{Elysia as bi}from"elysia";var D={AmazonCognito:Y,AniList:Q,Apple:G,Atlassian:V,Auth0:tt,Authentik:et,Bitbucket:nt,Box:it,Coinbase:ot,Discord:st,Dribbble:rt,Dropbox:ct,Facebook:at,Figma:ht,FortyTwo:Jt,GitHub:lt,GitLab:ut,Google:ft,Intuit:dt,Kakao:pt,KeyCloak:kt,Lichess:wt,Line:mt,Linear:xt,LinkedIn:gt,MicrosoftEntraId:It,MyAnimeList:At,Notion:zt,Okta:yt,Osu:bt,Patreon:Rt,Reddit:Ut,Roblox:Et,Salesforce:_t,Shikimori:St,Slack:vt,Spotify:Lt,Strava:Tt,Tiltify:Ct,Tumblr:Pt,Twitch:Bt,Twitter:Ht,VK:Nt,WorkOS:Ot,Yahoo:qt,Yandex:Mt,Zoom:Wt},Xe=Object.keys(D).reduce((e,t)=>{return e[t.toLowerCase()]=t,e},{});var Kt=(e)=>("refreshAccessToken"in e)&&typeof e.refreshAccessToken==="function",Ye=(e)=>("revokeAccessToken"in e)&&typeof e.revokeAccessToken==="function",B=(e)=>Object.keys(D).map((t)=>t.toLowerCase()).includes(e.toLowerCase()),Qe=(e)=>!0,Ze=(e)=>e!==null&&e!==void 0&&e.trim()!=="";var Ge=86400000;var $=1800;var Ve=({clientProviders:e,authorizeRoute:t="authorize",onAuthorize:n})=>new bi().get(`/${t}/:provider`,({error:i,redirect:o,cookie:{state:r,code_verifier:l,auth_provider:u,redirect_url:s},params:{provider:f},headers:k})=>{if(f===void 0)return i("Bad Request","Provider is required");if(!B(f))return i("Bad Request","Invalid provider");try{let w=f.toLowerCase(),{providerInstance:A,scopes:I,searchParams:x}=e[w],g=k.referer??"/";s.set({httpOnly:!0,maxAge:$,path:"/",sameSite:"lax",secure:!0,value:g}),u.set({httpOnly:!0,maxAge:$,path:"/",sameSite:"lax",secure:!0,value:f});let E=Yt();r.set({httpOnly:!0,maxAge:$,path:"/",sameSite:"lax",secure:!0,value:E});let v=A.createAuthorizationURL.toString().includes("codeVerifier"),C=v?Xt():void 0;v&&l.set({httpOnly:!0,maxAge:$,path:"/",sameSite:"lax",secure:!0,value:C??""});let H=v?A.createAuthorizationURL(E,C,I):A.createAuthorizationURL(E,I);return x.forEach(([q,M])=>{H.searchParams.set(q,M)}),n?.(),o(H.toString())}catch(w){if(w instanceof Error)return i("Internal Server Error",`${w.message} - ${w.stack??""}`);return i("Internal Server Error",`Unknown error: ${w}`)}});import{Elysia as Ui}from"elysia";import{Elysia as Ri}from"elysia";var O=()=>{let e={};return new Ri({name:"sessionStore"}).state({session:e})};var tn=({clientProviders:e,callbackRoute:t="authorize/callback",onCallback:n})=>new Ui().use(O()).get(`/${t}`,async({error:i,redirect:o,store:{session:r},cookie:{state:l,code_verifier:u,redirect_url:s,user_session_id:f,auth_provider:k},query:{code:w,state:A}})=>{if(!Ze(w)||l.value===void 0)return i("Bad Request","Invalid callback request");if(A!==l.value)return i("Bad Request","Invalid state mismatch");if(k.value===void 0)return i("Unauthorized","No auth provider found");if(!B(k.value))return i("Unauthorized","Invalid provider");let I=k.value.toLowerCase(),{providerInstance:x}=e[I];try{l.remove();let g=x.validateAuthorizationCode.toString().includes("codeVerifier"),E=u.value;if(g&&E===void 0)return i("Bad Request","Code verifier not found and is required");let v=E??"",C=await(g?x.validateAuthorizationCode(w,v):x.validateAuthorizationCode(w));if(g)u.remove();let H=Object.fromEntries(Object.entries(Gt(C.idToken())).map(([jt,F])=>[jt,typeof F==="string"?F:void 0])),q=k.value;await n?.({authProvider:q,decodedIdToken:H,session:r,user_session_id:f});let M=s.value??"/";return o(M)}catch(g){if(g instanceof Error)return i("Internal Server Error",`${g.message} - ${g.stack??""}`);return i("Internal Server Error",`Failed to validate authorization code: Unknown error: ${g}`)}});import{Elysia as Ei}from"elysia";var en=({logoutRoute:e="logout",onLogout:t})=>new Ei().post(`/${e}`,async({error:n,cookie:{user_session_id:i,auth_provider:o}})=>{if(o.value===void 0)return n("Unauthorized","No auth provider found");try{return t?.(),i.remove(),o.remove(),new Response("Succesfuly Logged Out",{status:204})}catch(r){if(r instanceof Error)return n("Internal Server Error",`Failed to logout: ${r.message}`);return n("Internal Server Error",`Failed to logout: Unknown error: ${r}`)}});import{Elysia as _i}from"elysia";var nn=()=>new _i().use(O()).derive(({store:{session:e},cookie:{user_session_id:t},error:n})=>({protectRoute:async(i,o)=>{if(t.value===void 0)return o?.()??n("Unauthorized","No session ID found");if(e[t.value]===void 0)return o?.()??n("Unauthorized","No session found");return i()}})).as("plugin");import{Elysia as Si}from"elysia";var on=({clientProviders:e,refreshRoute:t="refresh",onRefresh:n})=>new Si().post(`/${t}`,async({error:i,cookie:{user_refresh_token:o,auth_provider:r}})=>{if(o.value===void 0)return i("Unauthorized","No refresh token found");if(r.value===void 0)return i("Unauthorized","No auth provider found");let l=r.value.toLowerCase(),{providerInstance:u}=e[l];if(!Kt(u))return i("Not Implemented","Provider is not refreshable");try{return await u.refreshAccessToken(o.value),n?.(),new Response("Token refreshed",{status:204})}catch(s){if(s instanceof Error)return i("Internal Server Error",`Failed to refresh token: ${s.message}`);return i("Internal Server Error",`Faile to refresh token: Unknown error: ${s}`)}});import{Elysia as vi}from"elysia";var sn=({clientProviders:e,revokeRoute:t="revoke",onRevoke:n})=>new vi().post(`/${t}/access-token`,async({error:i,cookie:{user_refresh_token:o,auth_provider:r}})=>{if(o.value===void 0)return i("Unauthorized","No refresh token found");if(r.value===void 0)return i("Unauthorized","No auth provider found");let l=r.value.toLowerCase(),{providerInstance:u}=e[l];if(!Ye(u))return i("Not Implemented","Provider does not support revocation");try{return await u.revokeAccessToken(o.value),n?.(),new Response("Token revoked",{status:204})}catch(s){if(s instanceof Error)return i("Internal Server Error",`Failed to revoke token: ${s.message}`);return i("Internal Server Error",`Failed to revoke token: Unknown error: ${s}`)}});import{Elysia as Li}from"elysia";var rn=({clientProviders:e,statusRoute:t="auth-status",onStatus:n})=>new Li().use(O()).get(`/${t}`,async({error:i,cookie:{user_session_id:o,auth_provider:r},store:{session:l}})=>{try{if(o.value===void 0)return new Response(JSON.stringify({isLoggedIn:!1,user:null}),{headers:{"Content-Type":"application/json"}});if(r.value===void 0)return new Response(JSON.stringify({isLoggedIn:!1,user:null}),{headers:{"Content-Type":"application/json"}});let u=r.value.toLowerCase(),{providerInstance:s}=e[u];if(!Kt(s))return i("Not Implemented","Provider is not refreshable");let f=l[o.value];if(f===void 0)return new Response(JSON.stringify({isLoggedIn:!1,user:null}),{headers:{"Content-Type":"application/json"}});let{user:k}=f;return n?.(),new Response(JSON.stringify({isLoggedIn:!0,user:k}),{headers:{"Content-Type":"application/json"}})}catch(u){if(u instanceof Error)return i("Internal Server Error",`Error: ${u.message} - ${u.stack??""}`);return i("Internal Server Error",`Unknown Error: ${u}`)}});var ll=async({user_session_id:e,session:t,getUser:n,createUser:i})=>{let o=await n();if(o=o??await i(),!Qe(o))throw new Error("Internal Server Error - Invalid user schema");let r=crypto.randomUUID();t[r]={expiresAt:Date.now()+Ge,user:o},e.set({httpOnly:!0,sameSite:"lax",secure:!0,value:r})},ul=(e)=>e;var bl=({config:e,authorizeRoute:t,callbackRoute:n,logoutRoute:i,statusRoute:o,refreshRoute:r,revokeRoute:l,onAuthorize:u,onCallback:s,onStatus:f,onRefresh:k,onLogout:w,onRevoke:A})=>{let I=Object.keys(e).reduce((x,g)=>{if(!Object.prototype.hasOwnProperty.call(e,g))return x;if(!B(g))return console.error(`Provider ${g} is not supported`),x;let E=e[g];if(!E)return x;let v=g.toLowerCase(),C=Xe[v];if(!B(C))return console.error(`Provider ${g} is not supported`),x;let H=D[C],{credentials:q,scopes:M=[],searchParams:jt=[]}=E,F=new H(...q);return x[v]={providerInstance:F,scopes:M,searchParams:jt},x},{});return new Ti().error("OAUTH2_REQUEST_ERROR",K).error("ARCTIC_FETCH_ERROR",T).use(en({logoutRoute:i,onLogout:w})).use(sn({clientProviders:I,onRevoke:A,revokeRoute:l})).use(rn({clientProviders:I,onStatus:f,statusRoute:o})).use(on({clientProviders:I,onRefresh:k,refreshRoute:r})).use(Ve({authorizeRoute:t,clientProviders:I,onAuthorize:u})).use(tn({callbackRoute:n,clientProviders:I,onCallback:s})).use(nn()).as("plugin")};export{ll as instantiateUserSession,ul as createAuthConfig,bl as absoluteAuth};
2
+ import{OAuth2RequestError as oN,ArcticFetchError as sN}from"arctic";import{Elysia as aN}from"elysia";import{generateState as RN,generateCodeVerifier as bN}from"arctic";import{Elysia as kN}from"elysia";import{AmazonCognito as l,AniList as u,Apple as c,Atlassian as d,Auth0 as t,Authentik as o,Bitbucket as s,Box as a,Coinbase as i,Discord as e,Dribbble as r,Dropbox as NN,Facebook as EN,Figma as IN,Intuit as SN,GitHub as UN,GitLab as mN,Google as MN,Kakao as TN,KeyCloak as wN,Lichess as xN,Line as DN,Linear as ON,LinkedIn as $N,MicrosoftEntraId as AN,MyAnimeList as LN,Notion as HN,Okta as CN,Osu as JN,Patreon as QN,Reddit as XN,Roblox as YN,Salesforce as jN,Shikimori as FN,Slack as WN,Spotify as ZN,Strava as qN,Tiltify as BN,Tumblr as nN,Twitch as GN,Twitter as VN,VK as KN,WorkOS as gN,Yahoo as pN,Yandex as zN,Zoom as PN,FortyTwo as fN}from"arctic";var Z={AmazonCognito:l,AniList:u,Apple:c,Atlassian:d,Auth0:t,Authentik:o,Bitbucket:s,Box:a,Coinbase:i,Discord:e,Dribbble:r,Dropbox:NN,Facebook:EN,Figma:IN,FortyTwo:fN,GitHub:UN,GitLab:mN,Google:MN,Intuit:SN,Kakao:TN,KeyCloak:wN,Lichess:xN,Line:DN,Linear:ON,LinkedIn:$N,MicrosoftEntraId:AN,MyAnimeList:LN,Notion:HN,Okta:CN,Osu:JN,Patreon:QN,Reddit:XN,Roblox:YN,Salesforce:jN,Shikimori:FN,Slack:WN,Spotify:ZN,Strava:qN,Tiltify:BN,Tumblr:nN,Twitch:GN,Twitter:VN,VK:KN,WorkOS:gN,Yahoo:pN,Yandex:zN,Zoom:PN},K=Object.keys(Z).reduce((N,m)=>{return N[m.toLowerCase()]=m,N},{});var B=(N)=>("refreshAccessToken"in N)&&typeof N.refreshAccessToken==="function",g=(N)=>("revokeAccessToken"in N)&&typeof N.revokeAccessToken==="function",Y=(N)=>Object.keys(Z).map((m)=>m.toLowerCase()).includes(N.toLowerCase()),p=(N)=>!0,z=(N)=>N!==null&&N!==void 0&&N.trim()!=="";var P=86400000;var q=1800;var f=({clientProviders:N,authorizeRoute:m="authorize",onAuthorize:I})=>new kN().get(`/${m}/:provider`,({error:E,redirect:S,cookie:{state:U,code_verifier:x,auth_provider:M,redirect_url:T},params:{provider:D},headers:A})=>{if(D===void 0)return E("Bad Request","Provider is required");if(!Y(D))return E("Bad Request","Invalid provider");try{let O=D.toLowerCase(),{providerInstance:X,scopes:L,searchParams:$}=N[O],w=A.referer??"/";T.set({httpOnly:!0,maxAge:q,path:"/",sameSite:"lax",secure:!0,value:w}),M.set({httpOnly:!0,maxAge:q,path:"/",sameSite:"lax",secure:!0,value:D});let H=RN();U.set({httpOnly:!0,maxAge:q,path:"/",sameSite:"lax",secure:!0,value:H});let C=X.createAuthorizationURL.toString().includes("codeVerifier"),J=C?bN():void 0;C&&x.set({httpOnly:!0,maxAge:q,path:"/",sameSite:"lax",secure:!0,value:J??""});let Q=C?X.createAuthorizationURL(H,J,L):X.createAuthorizationURL(H,L);return $.forEach(([j,W])=>{Q.searchParams.set(j,W)}),I?.(),S(Q.toString())}catch(O){if(O instanceof Error)return E("Internal Server Error",`${O.message} - ${O.stack??""}`);return E("Internal Server Error",`Unknown error: ${O}`)}});import{decodeIdToken as vN}from"arctic";import{Elysia as hN}from"elysia";import{Elysia as yN}from"elysia";var F=()=>{let N={};return new yN({name:"sessionStore"}).state({session:N})};async function R(N,m){let I=_N[N];if(!I)throw new Error(`Unknown provider: ${N}`);let E=I.endpoint,S=I.method??"GET",U={};if(I.headers)Object.assign(U,I.headers);if(I.authIn==="header")U.Authorization=`Bearer ${m}`;else{let T=I.tokenParam??"access_token",D=E.includes("?")?"&":"?";E=`${E}${D}${T}=${encodeURIComponent(m)}`}let x={method:S,headers:U};if(S==="POST"&&I.body)U["Content-Type"]="application/json",x.body=JSON.stringify(I.body);let M=await fetch(E,x);if(!M.ok){let T=await M.text();throw new Error(`Failed to fetch ${N} profile: ${M.status} ${T}`)}return M.json()}var _N={facebook:{endpoint:"https://graph.facebook.com/me?fields=id,name,picture,email",method:"GET",authIn:"query",tokenParam:"access_token"},anilist:{endpoint:"https://graphql.anilist.co",method:"POST",authIn:"header",headers:{"Content-Type":"application/json",Accept:"application/json"},body:{query:"query { Viewer { id name } }"}},atlassian:{endpoint:"https://api.atlassian.com/me",method:"GET",authIn:"header"},battlenet:{endpoint:"https://oauth.battle.net/userinfo",method:"GET",authIn:"header"},bitbucket:{endpoint:"https://api.bitbucket.org/2.0/user",method:"GET",authIn:"header"},box:{endpoint:"https://api.box.com/2.0/users/me",method:"GET",authIn:"header"},bungie:{endpoint:"https://www.bungie.net/Platform/User/GetCurrentBungieNetUser",method:"GET",authIn:"header",headers:{"X-API-Key":"<YOUR_API_KEY>"}},coinbase:{endpoint:"https://api.coinbase.com/v2/user",method:"GET",authIn:"header"},discord:{endpoint:"https://discord.com/api/users/@me",method:"GET",authIn:"header"},donationAlerts:{endpoint:"https://www.donationalerts.com/api/v1/user",method:"GET",authIn:"header"},dribbble:{endpoint:"https://api.dribbble.com/v2/user",method:"GET",authIn:"header"},dropbox:{endpoint:"https://api.dropboxapi.com/2/users/get_current_account",method:"GET",authIn:"header"},epicGames:{endpoint:"https://api.epicgames.dev/epic/oauth/v2/userInfo",method:"GET",authIn:"header"},etsy:{endpoint:"https://openapi.etsy.com/v3/application/users/me",method:"GET",authIn:"header"},figma:{endpoint:"https://api.figma.com/v1/me",method:"GET",authIn:"header"},gitea:{endpoint:"https://<YOUR_GITEA_DOMAIN>/api/v1/user",method:"GET",authIn:"header"},github:{endpoint:"https://api.github.com/user",method:"GET",authIn:"header"},gitlab:{endpoint:"https://gitlab.com/api/v4/user",method:"GET",authIn:"header"},intuit:{endpoint:"https://oauth.platform.intuit.com/oauth2/v1/userinfo",method:"GET",authIn:"header"},kakao:{endpoint:"https://kapi.kakao.com/v2/user/me",method:"GET",authIn:"header"},kick:{endpoint:"https://api.kick.com/v1/user",method:"GET",authIn:"header"},lichess:{endpoint:"https://lichess.org/api/account",method:"GET",authIn:"header"},line:{endpoint:"https://api.line.me/v2/profile",method:"GET",authIn:"header"},linear:{endpoint:"https://api.linear.app/graphql",method:"POST",authIn:"header",headers:{"Content-Type":"application/json",Accept:"application/json"},body:{query:"query { viewer { id name } }"}},mastodon:{endpoint:"https://<YOUR_INSTANCE>/api/v1/accounts/verify_credentials",method:"GET",authIn:"header"},mercadoLibre:{endpoint:"https://api.mercadolibre.com/users/me",method:"GET",authIn:"header"},mercadoPago:{endpoint:"https://api.mercadopago.com/v1/users/me",method:"GET",authIn:"header"},myAnimeList:{endpoint:"https://api.myanimelist.net/v2/users/@me",method:"GET",authIn:"header"},naver:{endpoint:"https://openapi.naver.com/v1/nid/me",method:"GET",authIn:"header"},notion:{endpoint:"https://api.notion.com/v1/users/me",method:"GET",authIn:"header"},osu:{endpoint:"https://osu.ppy.sh/api/v2/me",method:"GET",authIn:"header"},patreon:{endpoint:"https://www.patreon.com/api/oauth2/v2/identity",method:"GET",authIn:"header"},polar:{endpoint:"https://www.polaraccesslink.com/v3/users/<USER_ID>",method:"GET",authIn:"header"},reddit:{endpoint:"https://oauth.reddit.com/api/v1/me",method:"GET",authIn:"header"},roblox:{endpoint:"https://apis.roblox.com/oauth/v1/userinfo",method:"GET",authIn:"header"},shikimori:{endpoint:"https://shikimori.one/api/users/whoami",method:"GET",authIn:"header"},slack:{endpoint:"https://slack.com/api/users.identity",method:"GET",authIn:"query",tokenParam:"token"},spotify:{endpoint:"https://api.spotify.com/v1/me",method:"GET",authIn:"header"},startGg:{endpoint:"https://api.start.gg/gql/alpha",method:"POST",authIn:"header",headers:{"Content-Type":"application/json",Accept:"application/json"},body:{query:"query { currentUser { id slug email player { gamerTag } } }"}},strava:{endpoint:"https://www.strava.com/api/v3/athlete",method:"GET",authIn:"header"},synology:{endpoint:"https://<YOUR_DOMAIN>/webman/sso/SSOUserInfo.cgi",method:"GET",authIn:"header"},tiktok:{endpoint:"https://open.douyin.com/oauth/userinfo",method:"GET",authIn:"query",tokenParam:"access_token"},tiltify:{endpoint:"https://tiltify.com/api/v3/me",method:"GET",authIn:"header"},tumblr:{endpoint:"https://api.tumblr.com/v2/user/info",method:"GET",authIn:"header"},twitch:{endpoint:"https://api.twitch.tv/helix/users",method:"GET",authIn:"header"},twitter:{endpoint:"https://api.twitter.com/2/users/me",method:"GET",authIn:"header"},vk:{endpoint:"https://api.vk.com/method/users.get",method:"GET",authIn:"query",tokenParam:"access_token"},zoom:{endpoint:"https://api.zoom.us/v2/users/me",method:"GET",authIn:"header"}};var b=({clientProviders:N,callbackRoute:m="authorize/callback",onCallback:I})=>new hN().use(F()).get(`/${m}`,async({error:E,redirect:S,store:{session:U},cookie:{state:x,code_verifier:M,redirect_url:T,user_session_id:D,auth_provider:A},query:{code:O,state:X}})=>{if(!z(O)||x.value===void 0)return E("Bad Request","Invalid callback request");if(X!==x.value)return E("Bad Request","Invalid state mismatch");if(A.value===void 0)return E("Unauthorized","No auth provider found");if(!Y(A.value))return E("Unauthorized","Invalid provider");let L=A.value.toLowerCase(),{providerInstance:$}=N[L];try{x.remove();let w=$.validateAuthorizationCode.toString().includes("codeVerifier"),H=M.value;if(w&&H===void 0)return E("Bad Request","Code verifier not found and is required");let C=H??"",J=await(w?$.validateAuthorizationCode(O,C):$.validateAuthorizationCode(O));if(w)M.remove();let Q,j=A.value;try{Q=Object.fromEntries(Object.entries(vN(J.idToken())).map(([G,V])=>[G,typeof V==="string"?V:void 0]))}catch(n){Q=await R(j,J.accessToken())}await I?.({authProvider:j,userProfile:Q,session:U,user_session_id:D});let W=T.value??"/";return S(W)}catch(w){if(w instanceof Error)return E("Internal Server Error",`${w.message} - ${w.stack??""}`);return E("Internal Server Error",`Failed to validate authorization code: Unknown error: ${w}`)}});import{Elysia as lN}from"elysia";var k=({logoutRoute:N="logout",onLogout:m})=>new lN().post(`/${N}`,async({error:I,cookie:{user_session_id:E,auth_provider:S}})=>{if(S.value===void 0)return I("Unauthorized","No auth provider found");try{return m?.(),E.remove(),S.remove(),new Response("Succesfuly Logged Out",{status:204})}catch(U){if(U instanceof Error)return I("Internal Server Error",`Failed to logout: ${U.message}`);return I("Internal Server Error",`Failed to logout: Unknown error: ${U}`)}});import{Elysia as uN}from"elysia";var y=()=>new uN().use(F()).derive(({store:{session:N},cookie:{user_session_id:m},error:I})=>({protectRoute:async(E,S)=>{if(m.value===void 0)return S?.()??I("Unauthorized","No session ID found");if(N[m.value]===void 0)return S?.()??I("Unauthorized","No session found");return E()}})).as("plugin");import{Elysia as cN}from"elysia";var _=({clientProviders:N,refreshRoute:m="refresh",onRefresh:I})=>new cN().post(`/${m}`,async({error:E,cookie:{user_refresh_token:S,auth_provider:U}})=>{if(S.value===void 0)return E("Unauthorized","No refresh token found");if(U.value===void 0)return E("Unauthorized","No auth provider found");let x=U.value.toLowerCase(),{providerInstance:M}=N[x];if(!B(M))return E("Not Implemented","Provider is not refreshable");try{return await M.refreshAccessToken(S.value),I?.(),new Response("Token refreshed",{status:204})}catch(T){if(T instanceof Error)return E("Internal Server Error",`Failed to refresh token: ${T.message}`);return E("Internal Server Error",`Faile to refresh token: Unknown error: ${T}`)}});import{Elysia as dN}from"elysia";var v=({clientProviders:N,revokeRoute:m="revoke",onRevoke:I})=>new dN().post(`/${m}/access-token`,async({error:E,cookie:{user_refresh_token:S,auth_provider:U}})=>{if(S.value===void 0)return E("Unauthorized","No refresh token found");if(U.value===void 0)return E("Unauthorized","No auth provider found");let x=U.value.toLowerCase(),{providerInstance:M}=N[x];if(!g(M))return E("Not Implemented","Provider does not support revocation");try{return await M.revokeAccessToken(S.value),I?.(),new Response("Token revoked",{status:204})}catch(T){if(T instanceof Error)return E("Internal Server Error",`Failed to revoke token: ${T.message}`);return E("Internal Server Error",`Failed to revoke token: Unknown error: ${T}`)}});import{Elysia as tN}from"elysia";var h=({clientProviders:N,statusRoute:m="auth-status",onStatus:I})=>new tN().use(F()).get(`/${m}`,async({error:E,cookie:{user_session_id:S,auth_provider:U},store:{session:x}})=>{try{if(S.value===void 0)return new Response(JSON.stringify({isLoggedIn:!1,user:null}),{headers:{"Content-Type":"application/json"}});if(U.value===void 0)return new Response(JSON.stringify({isLoggedIn:!1,user:null}),{headers:{"Content-Type":"application/json"}});let M=U.value.toLowerCase(),{providerInstance:T}=N[M];if(!B(T))return E("Not Implemented","Provider is not refreshable");let D=x[S.value];if(D===void 0)return new Response(JSON.stringify({isLoggedIn:!1,user:null}),{headers:{"Content-Type":"application/json"}});let{user:A}=D;return I?.(),new Response(JSON.stringify({isLoggedIn:!0,user:A}),{headers:{"Content-Type":"application/json"}})}catch(M){if(M instanceof Error)return E("Internal Server Error",`Error: ${M.message} - ${M.stack??""}`);return E("Internal Server Error",`Unknown Error: ${M}`)}});var zE=async({user_session_id:N,session:m,getUser:I,createUser:E})=>{let S=await I();if(S=S??await E(),!p(S))throw new Error("Internal Server Error - Invalid user schema");let U=crypto.randomUUID();m[U]={expiresAt:Date.now()+P,user:S},N.set({httpOnly:!0,sameSite:"lax",secure:!0,value:U})},PE=(N)=>N;var tE=({config:N,authorizeRoute:m,callbackRoute:I,logoutRoute:E,statusRoute:S,refreshRoute:U,revokeRoute:x,onAuthorize:M,onCallback:T,onStatus:D,onRefresh:A,onLogout:O,onRevoke:X})=>{let L=Object.keys(N).reduce(($,w)=>{if(!Object.prototype.hasOwnProperty.call(N,w))return $;if(!Y(w))return console.error(`Provider ${w} is not supported`),$;let H=N[w];if(!H)return $;let C=w.toLowerCase(),J=K[C];if(!Y(J))return console.error(`Provider ${w} is not supported`),$;let Q=Z[J],{credentials:j,scopes:W=[],searchParams:n=[]}=H,G=new Q(...j);return $[C]={providerInstance:G,scopes:W,searchParams:n},$},{});return new aN().error("OAUTH2_REQUEST_ERROR",oN).error("ARCTIC_FETCH_ERROR",sN).use(k({logoutRoute:E,onLogout:O})).use(v({clientProviders:L,onRevoke:X,revokeRoute:x})).use(h({clientProviders:L,onStatus:D,statusRoute:S})).use(_({clientProviders:L,onRefresh:A,refreshRoute:U})).use(f({authorizeRoute:m,clientProviders:L,onAuthorize:M})).use(b({callbackRoute:I,clientProviders:L,onCallback:T})).use(y()).as("plugin")};export{zE as instantiateUserSession,PE as createAuthConfig,tE as absoluteAuth};
@@ -0,0 +1,10 @@
1
+ export type ProfileRequest = {
2
+ endpoint: string;
3
+ method?: 'GET' | 'POST';
4
+ authIn: 'header' | 'query';
5
+ tokenParam?: string;
6
+ headers?: Record<string, string>;
7
+ body?: any;
8
+ };
9
+ export declare function fetchUserProfile(provider: string, accessToken: string): Promise<any>;
10
+ export declare const profileConfigs: Record<string, ProfileRequest>;
@@ -15,15 +15,15 @@ export type Providers = keyof typeof providers;
15
15
  export type SessionRecord<UserType> = Record<string, SessionData<UserType> | undefined>;
16
16
  export type UserFunctionProps = {
17
17
  authProvider: string;
18
- decodedIdToken: {
18
+ userProfile: {
19
19
  [key: string]: string | undefined;
20
20
  };
21
21
  };
22
- export type CreateUser<UserType> = ({ decodedIdToken, authProvider }: UserFunctionProps) => Promise<UserType>;
23
- export type GetUser<UserType> = ({ decodedIdToken, authProvider }: UserFunctionProps) => Promise<UserType | null>;
24
- export type OnCallback<UserType> = ({ authProvider, decodedIdToken, session, user_session_id }: {
22
+ export type CreateUser<UserType> = ({ userProfile, authProvider }: UserFunctionProps) => Promise<UserType>;
23
+ export type GetUser<UserType> = ({ userProfile, authProvider }: UserFunctionProps) => Promise<UserType | null>;
24
+ export type OnCallback<UserType> = ({ authProvider, userProfile, session, user_session_id }: {
25
25
  authProvider: string;
26
- decodedIdToken: {
26
+ userProfile: {
27
27
  [key: string]: string | undefined;
28
28
  };
29
29
  session: SessionRecord<UserType>;
@@ -49,4 +49,14 @@ export type ClientProviders = Record<string, {
49
49
  scopes: string[];
50
50
  searchParams: [string, string][];
51
51
  }>;
52
+ export type InsantiateUserSessionProps<UserType> = {
53
+ authProvider: string;
54
+ userProfile: {
55
+ [key: string]: string | undefined;
56
+ };
57
+ session: SessionRecord<UserType>;
58
+ user_session_id: Cookie<string | undefined>;
59
+ createUser: () => UserType | Promise<UserType>;
60
+ getUser: () => UserType | Promise<UserType | null>;
61
+ };
52
62
  export {};
@@ -1,15 +1,3 @@
1
- import { Cookie } from 'elysia';
2
- import { AbsoluteAuthProps, SessionRecord } from './types';
3
- type InsantiateUserSessionProps<UserType> = {
4
- authProvider: string;
5
- decodedIdToken: {
6
- [key: string]: string | undefined;
7
- };
8
- session: SessionRecord<UserType>;
9
- user_session_id: Cookie<string | undefined>;
10
- createUser: () => UserType | Promise<UserType>;
11
- getUser: () => UserType | Promise<UserType | null>;
12
- };
1
+ import { AbsoluteAuthProps, InsantiateUserSessionProps } from './types';
13
2
  export declare const instantiateUserSession: <UserType>({ user_session_id, session, getUser, createUser }: InsantiateUserSessionProps<UserType>) => Promise<void>;
14
3
  export declare const createAuthConfig: <UserType>(props: AbsoluteAuthProps<UserType>) => AbsoluteAuthProps<UserType>;
15
- export {};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.1",
2
+ "version": "0.4.0",
3
3
  "name": "@absolutejs/auth",
4
4
  "description": "An authorization library for absolutejs",
5
5
  "repository": {
@@ -10,7 +10,7 @@
10
10
  "license": "CC BY-NC 4.0",
11
11
  "author": "Alex Kahn",
12
12
  "scripts": {
13
- "build": "rm -rf dist && bun build src/index.ts --outdir dist --minify --splitting --target=bun --external elysia && tsc --emitDeclarationOnly --project tsconfig.json",
13
+ "build": "rm -rf dist && bun build src/index.ts --outdir dist --minify --splitting --target=bun --external arctic --external elysia && tsc --emitDeclarationOnly --project tsconfig.json",
14
14
  "test": "echo \"Error: no test specified\" && exit 1",
15
15
  "format": "prettier --write \"./**/*.{js,jsx,ts,tsx,css,json}\"",
16
16
  "dev": "bun run --watch example/server.ts",
@@ -27,13 +27,12 @@
27
27
  "oauth"
28
28
  ],
29
29
  "types": "dist/src/index.d.ts",
30
- "dependencies": {
31
- "arctic": "3.6.0"
32
- },
33
30
  "peerDependencies": {
31
+ "arctic": ">= 3.6.0",
34
32
  "elysia": ">= 1.2.0"
35
33
  },
36
34
  "devDependencies": {
35
+ "arctic": "3.6.0",
37
36
  "@elysiajs/static": "1.2.0",
38
37
  "@neondatabase/serverless": "1.0.0",
39
38
  "@types/bun": "1.2.9",
package/src/callback.ts CHANGED
@@ -3,6 +3,7 @@ import { Elysia } from 'elysia';
3
3
  import { sessionStore } from './sessionStore';
4
4
  import { isNonEmptyString, isValidProviderKey } from './typeGuards';
5
5
  import { ClientProviders, OnCallback } from './types';
6
+ import { fetchUserProfile } from './profiles';
6
7
 
7
8
  type CallbackProps<UserType> = {
8
9
  clientProviders: ClientProviders;
@@ -78,22 +79,36 @@ export const callback = <UserType>({
78
79
  )
79
80
  : // @ts-expect-error - This is a dynamic check
80
81
  providerInstance.validateAuthorizationCode(code));
81
- if (hasCodeVerifier) code_verifier.remove();
82
82
 
83
- const decodedIdToken = Object.fromEntries(
84
- Object.entries(decodeIdToken(tokens.idToken())).map(
85
- ([key, value]) => [
86
- key,
87
- typeof value === 'string' ? value : undefined
88
- ]
89
- )
90
- );
83
+ if (hasCodeVerifier) code_verifier.remove();
91
84
 
85
+ let userProfile;
92
86
  const authProvider = auth_provider.value;
93
87
 
88
+ // TODO : Change if arctic ever updates
89
+ try {
90
+ const decodedIdToken = Object.fromEntries(
91
+ Object.entries(decodeIdToken(tokens.idToken())).map(
92
+ ([key, value]) => [
93
+ key,
94
+ typeof value === 'string'
95
+ ? value
96
+ : undefined
97
+ ]
98
+ )
99
+ );
100
+ userProfile = decodedIdToken;
101
+ } catch (err) {
102
+ // TODO : This has type any see if it can be fixed
103
+ userProfile = await fetchUserProfile(
104
+ authProvider,
105
+ tokens.accessToken()
106
+ );
107
+ }
108
+
94
109
  await onCallback?.({
95
110
  authProvider,
96
- decodedIdToken,
111
+ userProfile,
97
112
  session,
98
113
  user_session_id
99
114
  });
@@ -0,0 +1,322 @@
1
+ export type ProfileRequest = {
2
+ endpoint: string;
3
+ method?: 'GET' | 'POST';
4
+ authIn: 'header' | 'query';
5
+ tokenParam?: string;
6
+ headers?: Record<string, string>;
7
+ body?: any;
8
+ };
9
+
10
+ export async function fetchUserProfile(provider: string, accessToken: string) {
11
+ const cfg: ProfileRequest | undefined = profileConfigs[provider];
12
+ if (!cfg) {
13
+ throw new Error(`Unknown provider: ${provider}`);
14
+ }
15
+
16
+ let url = cfg.endpoint;
17
+ const method = cfg.method ?? 'GET';
18
+ const headers: Record<string, string> = {};
19
+
20
+ // Merge any static headers first
21
+ if (cfg.headers) {
22
+ Object.assign(headers, cfg.headers);
23
+ }
24
+
25
+ // Place token in header or query
26
+ if (cfg.authIn === 'header') {
27
+ headers['Authorization'] = `Bearer ${accessToken}`;
28
+ } else {
29
+ const tokenKey = cfg.tokenParam ?? 'access_token';
30
+ const sep = url.includes('?') ? '&' : '?';
31
+ url = `${url}${sep}${tokenKey}=${encodeURIComponent(accessToken)}`;
32
+ }
33
+
34
+ const init: RequestInit = { method, headers };
35
+
36
+ if (method === 'POST' && cfg.body) {
37
+ headers['Content-Type'] = 'application/json';
38
+ init.body = JSON.stringify(cfg.body);
39
+ }
40
+
41
+ const res = await fetch(url, init);
42
+ if (!res.ok) {
43
+ const errText = await res.text();
44
+ throw new Error(
45
+ `Failed to fetch ${provider} profile: ${res.status} ${errText}`
46
+ );
47
+ }
48
+
49
+ return res.json();
50
+ }
51
+
52
+ export const profileConfigs: Record<string, ProfileRequest> = {
53
+ facebook: {
54
+ endpoint: 'https://graph.facebook.com/me?fields=id,name,picture,email',
55
+ method: 'GET',
56
+ authIn: 'query',
57
+ tokenParam: 'access_token'
58
+ },
59
+ anilist: {
60
+ endpoint: 'https://graphql.anilist.co',
61
+ method: 'POST',
62
+ authIn: 'header',
63
+ headers: {
64
+ 'Content-Type': 'application/json',
65
+ Accept: 'application/json'
66
+ },
67
+ body: {
68
+ query: `query { Viewer { id name } }`
69
+ }
70
+ },
71
+ atlassian: {
72
+ endpoint: 'https://api.atlassian.com/me',
73
+ method: 'GET',
74
+ authIn: 'header'
75
+ },
76
+ battlenet: {
77
+ endpoint: 'https://oauth.battle.net/userinfo',
78
+ method: 'GET',
79
+ authIn: 'header'
80
+ },
81
+ bitbucket: {
82
+ endpoint: 'https://api.bitbucket.org/2.0/user',
83
+ method: 'GET',
84
+ authIn: 'header'
85
+ },
86
+ box: {
87
+ endpoint: 'https://api.box.com/2.0/users/me',
88
+ method: 'GET',
89
+ authIn: 'header'
90
+ },
91
+ bungie: {
92
+ endpoint:
93
+ 'https://www.bungie.net/Platform/User/GetCurrentBungieNetUser',
94
+ method: 'GET',
95
+ authIn: 'header',
96
+ headers: {
97
+ 'X-API-Key': '<YOUR_API_KEY>'
98
+ }
99
+ },
100
+ coinbase: {
101
+ endpoint: 'https://api.coinbase.com/v2/user',
102
+ method: 'GET',
103
+ authIn: 'header'
104
+ },
105
+ discord: {
106
+ endpoint: 'https://discord.com/api/users/@me',
107
+ method: 'GET',
108
+ authIn: 'header'
109
+ },
110
+ donationAlerts: {
111
+ endpoint: 'https://www.donationalerts.com/api/v1/user',
112
+ method: 'GET',
113
+ authIn: 'header'
114
+ },
115
+ dribbble: {
116
+ endpoint: 'https://api.dribbble.com/v2/user',
117
+ method: 'GET',
118
+ authIn: 'header'
119
+ },
120
+ dropbox: {
121
+ endpoint: 'https://api.dropboxapi.com/2/users/get_current_account',
122
+ method: 'GET',
123
+ authIn: 'header'
124
+ },
125
+ epicGames: {
126
+ endpoint: 'https://api.epicgames.dev/epic/oauth/v2/userInfo',
127
+ method: 'GET',
128
+ authIn: 'header'
129
+ },
130
+ etsy: {
131
+ endpoint: 'https://openapi.etsy.com/v3/application/users/me',
132
+ method: 'GET',
133
+ authIn: 'header'
134
+ },
135
+ figma: {
136
+ endpoint: 'https://api.figma.com/v1/me',
137
+ method: 'GET',
138
+ authIn: 'header'
139
+ },
140
+ gitea: {
141
+ endpoint: 'https://<YOUR_GITEA_DOMAIN>/api/v1/user',
142
+ method: 'GET',
143
+ authIn: 'header'
144
+ },
145
+ github: {
146
+ endpoint: 'https://api.github.com/user',
147
+ method: 'GET',
148
+ authIn: 'header'
149
+ },
150
+ gitlab: {
151
+ endpoint: 'https://gitlab.com/api/v4/user',
152
+ method: 'GET',
153
+ authIn: 'header'
154
+ },
155
+ intuit: {
156
+ endpoint: 'https://oauth.platform.intuit.com/oauth2/v1/userinfo',
157
+ method: 'GET',
158
+ authIn: 'header'
159
+ },
160
+ kakao: {
161
+ endpoint: 'https://kapi.kakao.com/v2/user/me',
162
+ method: 'GET',
163
+ authIn: 'header'
164
+ },
165
+ kick: {
166
+ endpoint: 'https://api.kick.com/v1/user',
167
+ method: 'GET',
168
+ authIn: 'header'
169
+ },
170
+ lichess: {
171
+ endpoint: 'https://lichess.org/api/account',
172
+ method: 'GET',
173
+ authIn: 'header'
174
+ },
175
+ line: {
176
+ endpoint: 'https://api.line.me/v2/profile',
177
+ method: 'GET',
178
+ authIn: 'header'
179
+ },
180
+ linear: {
181
+ endpoint: 'https://api.linear.app/graphql',
182
+ method: 'POST',
183
+ authIn: 'header',
184
+ headers: {
185
+ 'Content-Type': 'application/json',
186
+ Accept: 'application/json'
187
+ },
188
+ body: {
189
+ query: `query { viewer { id name } }`
190
+ }
191
+ },
192
+ mastodon: {
193
+ endpoint: 'https://<YOUR_INSTANCE>/api/v1/accounts/verify_credentials',
194
+ method: 'GET',
195
+ authIn: 'header'
196
+ },
197
+ mercadoLibre: {
198
+ endpoint: 'https://api.mercadolibre.com/users/me',
199
+ method: 'GET',
200
+ authIn: 'header'
201
+ },
202
+ mercadoPago: {
203
+ endpoint: 'https://api.mercadopago.com/v1/users/me',
204
+ method: 'GET',
205
+ authIn: 'header'
206
+ },
207
+ myAnimeList: {
208
+ endpoint: 'https://api.myanimelist.net/v2/users/@me',
209
+ method: 'GET',
210
+ authIn: 'header'
211
+ },
212
+ naver: {
213
+ endpoint: 'https://openapi.naver.com/v1/nid/me',
214
+ method: 'GET',
215
+ authIn: 'header'
216
+ },
217
+ notion: {
218
+ endpoint: 'https://api.notion.com/v1/users/me',
219
+ method: 'GET',
220
+ authIn: 'header'
221
+ },
222
+ osu: {
223
+ endpoint: 'https://osu.ppy.sh/api/v2/me',
224
+ method: 'GET',
225
+ authIn: 'header'
226
+ },
227
+ patreon: {
228
+ endpoint: 'https://www.patreon.com/api/oauth2/v2/identity',
229
+ method: 'GET',
230
+ authIn: 'header'
231
+ },
232
+ polar: {
233
+ endpoint: 'https://www.polaraccesslink.com/v3/users/<USER_ID>',
234
+ method: 'GET',
235
+ authIn: 'header'
236
+ },
237
+ reddit: {
238
+ endpoint: 'https://oauth.reddit.com/api/v1/me',
239
+ method: 'GET',
240
+ authIn: 'header'
241
+ },
242
+ roblox: {
243
+ endpoint: 'https://apis.roblox.com/oauth/v1/userinfo',
244
+ method: 'GET',
245
+ authIn: 'header'
246
+ },
247
+ shikimori: {
248
+ endpoint: 'https://shikimori.one/api/users/whoami',
249
+ method: 'GET',
250
+ authIn: 'header'
251
+ },
252
+ slack: {
253
+ endpoint: 'https://slack.com/api/users.identity',
254
+ method: 'GET',
255
+ authIn: 'query',
256
+ tokenParam: 'token'
257
+ },
258
+ spotify: {
259
+ endpoint: 'https://api.spotify.com/v1/me',
260
+ method: 'GET',
261
+ authIn: 'header'
262
+ },
263
+ startGg: {
264
+ endpoint: 'https://api.start.gg/gql/alpha',
265
+ method: 'POST',
266
+ authIn: 'header',
267
+ headers: {
268
+ 'Content-Type': 'application/json',
269
+ Accept: 'application/json'
270
+ },
271
+ body: {
272
+ query: `query { currentUser { id slug email player { gamerTag } } }`
273
+ }
274
+ },
275
+ strava: {
276
+ endpoint: 'https://www.strava.com/api/v3/athlete',
277
+ method: 'GET',
278
+ authIn: 'header'
279
+ },
280
+ synology: {
281
+ endpoint: 'https://<YOUR_DOMAIN>/webman/sso/SSOUserInfo.cgi',
282
+ method: 'GET',
283
+ authIn: 'header'
284
+ },
285
+ tiktok: {
286
+ endpoint: 'https://open.douyin.com/oauth/userinfo',
287
+ method: 'GET',
288
+ authIn: 'query',
289
+ tokenParam: 'access_token'
290
+ },
291
+ tiltify: {
292
+ endpoint: 'https://tiltify.com/api/v3/me',
293
+ method: 'GET',
294
+ authIn: 'header'
295
+ },
296
+ tumblr: {
297
+ endpoint: 'https://api.tumblr.com/v2/user/info',
298
+ method: 'GET',
299
+ authIn: 'header'
300
+ },
301
+ twitch: {
302
+ endpoint: 'https://api.twitch.tv/helix/users',
303
+ method: 'GET',
304
+ authIn: 'header'
305
+ },
306
+ twitter: {
307
+ endpoint: 'https://api.twitter.com/2/users/me',
308
+ method: 'GET',
309
+ authIn: 'header'
310
+ },
311
+ vk: {
312
+ endpoint: 'https://api.vk.com/method/users.get',
313
+ method: 'GET',
314
+ authIn: 'query',
315
+ tokenParam: 'access_token'
316
+ },
317
+ zoom: {
318
+ endpoint: 'https://api.zoom.us/v2/users/me',
319
+ method: 'GET',
320
+ authIn: 'header'
321
+ }
322
+ };
package/src/types.ts CHANGED
@@ -23,29 +23,29 @@ export type SessionRecord<UserType> = Record<
23
23
 
24
24
  export type UserFunctionProps = {
25
25
  authProvider: string;
26
- decodedIdToken: {
26
+ userProfile: {
27
27
  [key: string]: string | undefined;
28
28
  };
29
29
  };
30
30
 
31
31
  export type CreateUser<UserType> = ({
32
- decodedIdToken,
32
+ userProfile,
33
33
  authProvider
34
34
  }: UserFunctionProps) => Promise<UserType>;
35
35
 
36
36
  export type GetUser<UserType> = ({
37
- decodedIdToken,
37
+ userProfile,
38
38
  authProvider
39
39
  }: UserFunctionProps) => Promise<UserType | null>;
40
40
 
41
41
  export type OnCallback<UserType> = ({
42
42
  authProvider,
43
- decodedIdToken,
43
+ userProfile,
44
44
  session,
45
45
  user_session_id
46
46
  }: {
47
47
  authProvider: string;
48
- decodedIdToken: {
48
+ userProfile: {
49
49
  [key: string]: string | undefined;
50
50
  };
51
51
  session: SessionRecord<UserType>;
@@ -76,3 +76,14 @@ export type ClientProviders = Record<
76
76
  searchParams: [string, string][];
77
77
  }
78
78
  >;
79
+
80
+ export type InsantiateUserSessionProps<UserType> = {
81
+ authProvider: string;
82
+ userProfile: {
83
+ [key: string]: string | undefined;
84
+ };
85
+ session: SessionRecord<UserType>;
86
+ user_session_id: Cookie<string | undefined>;
87
+ createUser: () => UserType | Promise<UserType>;
88
+ getUser: () => UserType | Promise<UserType | null>;
89
+ };
package/src/utils.ts CHANGED
@@ -1,19 +1,7 @@
1
- import { Cookie } from 'elysia';
2
1
  import { MILLISECONDS_IN_A_DAY } from './constants';
3
- import { AbsoluteAuthProps, SessionRecord } from './types';
2
+ import { AbsoluteAuthProps, InsantiateUserSessionProps } from './types';
4
3
  import { isValidUser } from './typeGuards';
5
4
 
6
- type InsantiateUserSessionProps<UserType> = {
7
- authProvider: string;
8
- decodedIdToken: {
9
- [key: string]: string | undefined;
10
- };
11
- session: SessionRecord<UserType>;
12
- user_session_id: Cookie<string | undefined>;
13
- createUser: () => UserType | Promise<UserType>;
14
- getUser: () => UserType | Promise<UserType | null>;
15
- };
16
-
17
5
  export const instantiateUserSession = async <UserType>({
18
6
  user_session_id,
19
7
  session,