@@ -15,13 +15,16 @@ function getEncryptionKey(): string {
1515 return key ;
1616}
1717
18- export async function ensureSigningKey ( ) : Promise < void > {
19- const [ existingKey ] = await db
18+ async function selectActiveSigningKeys ( ) {
19+ return db
2020 . select ( )
2121 . from ( oauthSigningKeys )
2222 . where ( eq ( oauthSigningKeys . active , true ) )
23- . orderBy ( desc ( oauthSigningKeys . createdAt ) )
24- . limit ( 1 ) ;
23+ . orderBy ( desc ( oauthSigningKeys . createdAt ) ) ;
24+ }
25+
26+ export async function ensureSigningKey ( ) : Promise < void > {
27+ const [ existingKey ] = await selectActiveSigningKeys ( ) ;
2528
2629 if ( existingKey ) {
2730 return ;
@@ -57,12 +60,7 @@ export async function getActiveSigningKey(): Promise<{
5760 publicKeyPem : string ;
5861 privateKeyPem : string ;
5962} > {
60- const [ activeKey ] = await db
61- . select ( )
62- . from ( oauthSigningKeys )
63- . where ( eq ( oauthSigningKeys . active , true ) )
64- . orderBy ( desc ( oauthSigningKeys . createdAt ) )
65- . limit ( 1 ) ;
63+ const [ activeKey ] = await selectActiveSigningKeys ( ) ;
6664
6765 if ( ! activeKey ) {
6866 throw new Error ( "No active OAuth signing key found" ) ;
@@ -76,12 +74,24 @@ export async function getActiveSigningKey(): Promise<{
7674 } ;
7775}
7876
77+ export async function getActiveSigningPublicKeys ( ) : Promise <
78+ {
79+ keyId : string ;
80+ algorithm : string ;
81+ publicKeyPem : string ;
82+ } [ ]
83+ > {
84+ const activeKeys = await selectActiveSigningKeys ( ) ;
85+
86+ return activeKeys . map ( ( key ) => ( {
87+ keyId : key . keyId ,
88+ algorithm : key . algorithm ,
89+ publicKeyPem : key . publicKeyPem
90+ } ) ) ;
91+ }
92+
7993export async function getJWKS ( ) : Promise < JsonWebKey [ ] > {
80- const activeKeys = await db
81- . select ( )
82- . from ( oauthSigningKeys )
83- . where ( eq ( oauthSigningKeys . active , true ) )
84- . orderBy ( desc ( oauthSigningKeys . createdAt ) ) ;
94+ const activeKeys = await selectActiveSigningKeys ( ) ;
8595
8696 return activeKeys . map ( ( key ) => {
8797 const exported = createPublicKey ( key . publicKeyPem ) . export ( {
0 commit comments