chore: fix some more typescript errors
Signed-off-by: benjdlambert <ben@blam.sh>
This commit is contained in:
@@ -104,7 +104,7 @@ export class TestDatabases {
|
||||
if (supportedIds.length > 0) {
|
||||
afterAll(async () => {
|
||||
await databases.shutdown();
|
||||
});
|
||||
}, 30_000);
|
||||
}
|
||||
|
||||
return databases;
|
||||
|
||||
@@ -117,7 +117,7 @@ describe('Oidc Database', () => {
|
||||
codeChallenge: 'test-challenge',
|
||||
codeChallengeMethod: 'S256',
|
||||
nonce: 'test-nonce',
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
});
|
||||
|
||||
expect(session).toEqual(
|
||||
@@ -132,7 +132,7 @@ describe('Oidc Database', () => {
|
||||
codeChallenge: 'test-challenge',
|
||||
codeChallengeMethod: 'S256',
|
||||
nonce: 'test-nonce',
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
status: 'pending',
|
||||
}),
|
||||
);
|
||||
@@ -155,7 +155,7 @@ describe('Oidc Database', () => {
|
||||
clientId: client.clientId,
|
||||
redirectUri: 'https://example.com/callback',
|
||||
responseType: 'code',
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
});
|
||||
|
||||
await expect(
|
||||
@@ -190,20 +190,20 @@ describe('Oidc Database', () => {
|
||||
clientId: client.clientId,
|
||||
redirectUri: 'https://example.com/callback',
|
||||
responseType: 'code',
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
});
|
||||
|
||||
const authCode = await oidc.createAuthorizationCode({
|
||||
code: 'test-code',
|
||||
sessionId: session.id,
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
});
|
||||
|
||||
expect(authCode).toEqual(
|
||||
expect.objectContaining({
|
||||
code: 'test-code',
|
||||
sessionId: session.id,
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -230,13 +230,13 @@ describe('Oidc Database', () => {
|
||||
codeChallenge: 'test-challenge',
|
||||
codeChallengeMethod: 'S256',
|
||||
nonce: 'test-nonce',
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
});
|
||||
|
||||
const authCode = await oidc.createAuthorizationCode({
|
||||
code: 'test-code',
|
||||
sessionId: session.id,
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
});
|
||||
|
||||
const authCodeFromDb = await oidc.getAuthorizationCode({
|
||||
@@ -267,13 +267,13 @@ describe('Oidc Database', () => {
|
||||
clientId: client.clientId,
|
||||
redirectUri: 'https://example.com/callback',
|
||||
responseType: 'code',
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
});
|
||||
|
||||
const authCode = await oidc.createAuthorizationCode({
|
||||
code: 'test-code',
|
||||
sessionId: session.id,
|
||||
expiresAt: '2025-01-01T00:00:00Z',
|
||||
expiresAt: new Date('2025-01-01T00:00:00Z'),
|
||||
});
|
||||
|
||||
const updatedAuthCode = await oidc.updateAuthorizationCode({
|
||||
|
||||
@@ -16,6 +16,15 @@
|
||||
import { Knex } from 'knex';
|
||||
import { AuthDatabase } from './AuthDatabase';
|
||||
|
||||
function toDate(value?: Date | string | number): Date | undefined {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return typeof value === 'string' || typeof value === 'number'
|
||||
? new Date(value)
|
||||
: value;
|
||||
}
|
||||
type OidcClientRow = {
|
||||
client_id: string;
|
||||
client_secret: string;
|
||||
@@ -39,13 +48,13 @@ type OAuthAuthorizationSessionRow = {
|
||||
code_challenge_method: string | null;
|
||||
nonce: string | null;
|
||||
status: 'pending' | 'approved' | 'rejected' | 'expired';
|
||||
expires_at: string;
|
||||
expires_at: Date | string;
|
||||
};
|
||||
|
||||
type OidcAuthorizationCodeRow = {
|
||||
code: string;
|
||||
session_id: string;
|
||||
expires_at: string;
|
||||
expires_at: Date | string;
|
||||
used: boolean;
|
||||
};
|
||||
|
||||
@@ -72,26 +81,26 @@ export type AuthorizationSession = {
|
||||
codeChallengeMethod?: string;
|
||||
nonce?: string;
|
||||
status: 'pending' | 'approved' | 'rejected' | 'expired';
|
||||
expiresAt: string;
|
||||
expiresAt: Date;
|
||||
};
|
||||
|
||||
export type ConsentRequest = {
|
||||
id: string;
|
||||
sessionId: string;
|
||||
expiresAt: string;
|
||||
expiresAt: Date;
|
||||
};
|
||||
|
||||
export type AuthorizationCode = {
|
||||
code: string;
|
||||
sessionId: string;
|
||||
expiresAt: string;
|
||||
expiresAt: Date;
|
||||
used: boolean;
|
||||
};
|
||||
|
||||
export type AccessToken = {
|
||||
tokenId: string;
|
||||
sessionId: string;
|
||||
expiresAt: string;
|
||||
expiresAt: Date;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -342,7 +351,7 @@ export class OidcDatabase {
|
||||
codeChallengeMethod: row.code_challenge_method ?? undefined,
|
||||
nonce: row.nonce ?? undefined,
|
||||
status: row.status,
|
||||
expiresAt: row.expires_at,
|
||||
expiresAt: toDate(row.expires_at),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -363,7 +372,7 @@ export class OidcDatabase {
|
||||
return {
|
||||
code: row.code,
|
||||
sessionId: row.session_id,
|
||||
expiresAt: row.expires_at,
|
||||
expiresAt: toDate(row.expires_at),
|
||||
used: Boolean(row.used),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import { UserInfoDatabase } from '../database/UserInfoDatabase';
|
||||
import crypto from 'crypto';
|
||||
import { AnyJWK, TokenIssuer } from '../identity/types';
|
||||
|
||||
jest.setTimeout(60_000);
|
||||
|
||||
describe('OidcService', () => {
|
||||
const databases = TestDatabases.create();
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ export class OidcService {
|
||||
}
|
||||
|
||||
const sessionId = crypto.randomUUID();
|
||||
const sessionExpiresAt = DateTime.now().plus({ hours: 1 }).toISO();
|
||||
const sessionExpiresAt = DateTime.now().plus({ hours: 1 }).toJSDate();
|
||||
|
||||
await this.oidc.createAuthorizationSession({
|
||||
id: sessionId,
|
||||
@@ -211,7 +211,7 @@ export class OidcService {
|
||||
throw new NotFoundError('Invalid authorization session');
|
||||
}
|
||||
|
||||
if (DateTime.fromISO(session.expiresAt) < DateTime.now()) {
|
||||
if (DateTime.fromJSDate(session.expiresAt) < DateTime.now()) {
|
||||
throw new InputError('Authorization session expired');
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ export class OidcService {
|
||||
});
|
||||
|
||||
const authorizationCode = crypto.randomBytes(32).toString('base64url');
|
||||
const codeExpiresAt = DateTime.now().plus({ minutes: 10 }).toISO();
|
||||
const codeExpiresAt = DateTime.now().plus({ minutes: 10 }).toJSDate();
|
||||
|
||||
await this.oidc.createAuthorizationCode({
|
||||
code: authorizationCode,
|
||||
@@ -255,7 +255,7 @@ export class OidcService {
|
||||
throw new NotFoundError('Invalid authorization session');
|
||||
}
|
||||
|
||||
if (DateTime.fromISO(session.expiresAt) < DateTime.now()) {
|
||||
if (DateTime.fromJSDate(session.expiresAt) < DateTime.now()) {
|
||||
throw new InputError('Authorization session expired');
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ export class OidcService {
|
||||
throw new NotFoundError('Invalid authorization session');
|
||||
}
|
||||
|
||||
if (DateTime.fromISO(session.expiresAt) < DateTime.now()) {
|
||||
if (DateTime.fromJSDate(session.expiresAt) < DateTime.now()) {
|
||||
throw new InputError('Authorization session expired');
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ export class OidcService {
|
||||
}
|
||||
|
||||
const sessionId = crypto.randomUUID();
|
||||
const sessionExpiresAt = DateTime.now().plus({ hours: 1 }).toISO();
|
||||
const sessionExpiresAt = DateTime.now().plus({ hours: 1 }).toJSDate();
|
||||
|
||||
await this.oidc.createAuthorizationSession({
|
||||
id: sessionId,
|
||||
@@ -375,7 +375,7 @@ export class OidcService {
|
||||
});
|
||||
|
||||
const authorizationCode = crypto.randomBytes(32).toString('base64url');
|
||||
const codeExpiresAt = DateTime.now().plus({ minutes: 10 }).toISO();
|
||||
const codeExpiresAt = DateTime.now().plus({ minutes: 10 }).toJSDate();
|
||||
|
||||
await this.oidc.createAuthorizationCode({
|
||||
code: authorizationCode,
|
||||
@@ -429,7 +429,7 @@ export class OidcService {
|
||||
throw new AuthenticationError('Invalid authorization code');
|
||||
}
|
||||
|
||||
if (DateTime.fromISO(authCode.expiresAt) < DateTime.now()) {
|
||||
if (DateTime.fromJSDate(authCode.expiresAt) < DateTime.now()) {
|
||||
throw new AuthenticationError('Authorization code expired');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user