Compare commits

...

4 Commits

Author SHA1 Message Date
Sean Goedecke c05344404e Merge pull request #58 from actions/sgoedecke/fixup-bundle
Fixup bundle
2025-07-16 17:33:26 +10:00
Sean Goedecke aff9eb000b Fixup bundle 2025-07-16 07:30:35 +00:00
Sean Goedecke 0479ac822e Merge pull request #57 from actions/sgoedecke/package-pkce-lib-properly
Ensure pkce-challenge is bundled in dist instead of treated as external
2025-07-16 17:24:39 +10:00
Sean Goedecke 5a874b9aa1 Ensure pkce-challenge is bundled in dist instead of treated as external 2025-07-16 07:12:45 +00:00
3 changed files with 78 additions and 5 deletions
Generated Vendored
+67 -1
View File
@@ -30,7 +30,6 @@ import require$$6 from 'string_decoder';
import require$$0$9 from 'diagnostics_channel';
import require$$2$2 from 'child_process';
import require$$6$1 from 'timers';
import pkceChallenge from 'pkce-challenge';
import * as os from 'node:os';
import { EOL } from 'node:os';
import * as process$1 from 'node:process';
@@ -40630,6 +40629,73 @@ class Client extends Protocol {
}
}
let crypto;
crypto =
globalThis.crypto?.webcrypto ?? // Node.js [18-16] REPL
globalThis.crypto ?? // Node.js >18
import('node:crypto').then(m => m.webcrypto); // Node.js <18 Non-REPL
/**
* Creates an array of length `size` of random bytes
* @param size
* @returns Array of random ints (0 to 255)
*/
async function getRandomValues(size) {
return (await crypto).getRandomValues(new Uint8Array(size));
}
/** Generate cryptographically strong random string
* @param size The desired length of the string
* @returns The random string
*/
async function random(size) {
const mask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
let result = "";
const randomUints = await getRandomValues(size);
for (let i = 0; i < size; i++) {
// cap the value of the randomIndex to mask.length - 1
const randomIndex = randomUints[i] % mask.length;
result += mask[randomIndex];
}
return result;
}
/** Generate a PKCE challenge verifier
* @param length Length of the verifier
* @returns A random verifier `length` characters long
*/
async function generateVerifier(length) {
return await random(length);
}
/** Generate a PKCE code challenge from a code verifier
* @param code_verifier
* @returns The base64 url encoded code challenge
*/
async function generateChallenge(code_verifier) {
const buffer = await (await crypto).subtle.digest("SHA-256", new TextEncoder().encode(code_verifier));
// Generate base64url string
// btoa is deprecated in Node.js but is used here for web browser compatibility
// (which has no good replacement yet, see also https://github.com/whatwg/html/issues/6811)
return btoa(String.fromCharCode(...new Uint8Array(buffer)))
.replace(/\//g, '_')
.replace(/\+/g, '-')
.replace(/=/g, '');
}
/** Generate a PKCE challenge pair
* @param length Length of the verifer (between 43-128). Defaults to 43.
* @returns PKCE challenge pair
*/
async function pkceChallenge(length) {
if (!length)
length = 43;
if (length < 43 || length > 128) {
throw `Expected a length between 43 and 128. Received ${length}.`;
}
const verifier = await generateVerifier(length);
const challenge = await generateChallenge(verifier);
return {
code_verifier: verifier,
code_challenge: challenge,
};
}
/**
* RFC 9728 OAuth Protected Resource Metadata
*/
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -3
View File
@@ -1,5 +1,5 @@
// See: https://rollupjs.org/introduction/
import { builtinModules } from 'node:module'
import commonjs from '@rollup/plugin-commonjs'
import nodeResolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
@@ -13,10 +13,17 @@ const config = {
format: 'es',
sourcemap: true
},
external: [...builtinModules, /^node:/],
plugins: [
typescript(),
nodeResolve({ preferBuiltins: true }),
commonjs(),
nodeResolve({
preferBuiltins: true,
browser: false,
exportConditions: ['node']
}),
commonjs({
include: /node_modules/
}),
json()
]
}