deno.land / x / oauth4webapi@v1.2.2 / tap / modulus_length.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263import type QUnit from 'qunit'import * as lib from '../src/index.js'
const client = <lib.Client>{ client_id: 'urn:example:client_id',}const identifier = 'https://op.example.com'const issuer = <lib.AuthorizationServer>{ issuer: identifier,}
export default async (QUnit: QUnit) => { const { module, test } = QUnit module('modulus_length.ts')
for (const [alg, { privateKey, publicKey }] of Object.entries({ RS256: await lib.generateKeyPair('RS256', { modulusLength: 1024 }), PS256: await lib.generateKeyPair('PS256', { modulusLength: 1024 }), })) { test(`(DPoP) ${alg} private key modulus length must be at least 2048 bits long`, async (t) => { await t.rejects( lib.protectedResourceRequest( 'accessToken', 'GET', new URL('https://rs.example.com/api'), new Headers(), null, { DPoP: { privateKey, publicKey } }, ), (err: Error) => { t.propContains(err, { message: `${privateKey.algorithm.name} modulusLength must be at least 2048 bits`, }) return true }, ) })
test(`(private_key_jwt) ${alg} private key modulus length must be at least 2048 bits long`, async (t) => { await t.rejects( lib.pushedAuthorizationRequest( { ...issuer, pushed_authorization_request_endpoint: `${issuer.issuer}/par`, }, { ...client, token_endpoint_auth_method: 'private_key_jwt', }, new URLSearchParams(), { clientPrivateKey: privateKey }, ), (err: Error) => { t.propContains(err, { message: `${privateKey.algorithm.name} modulusLength must be at least 2048 bits`, }) return true }, ) }) }}
Version Info