Skip to content

Commit

Permalink
Removed jwsk cache, harmonized config with PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
corbadoman committed Jan 18, 2024
1 parent 8a530a3 commit b164682
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 28 deletions.
13 changes: 0 additions & 13 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export interface ConfigInterface {
FrontendAPI: string;
BackendAPI: string;
ShortSessionCookieName: string;
JWTIssuer: string;
JWKSCache: MemoryCache<string, string>;
CacheMaxAge: number;
}

Expand Down Expand Up @@ -39,10 +37,6 @@ class Config implements ConfigInterface {

CacheMaxAge: number = DefaultCacheMaxAge;

JWTIssuer: string;

JWKSCache: MemoryCache<string, string>;

constructor(projectID: string, apiSecret: string) {
this.validateProjectID(projectID);
this.validateAPISecret(apiSecret);
Expand All @@ -51,8 +45,6 @@ class Config implements ConfigInterface {
this.APISecret = apiSecret;
this.Client = DefaultClient;
this.FrontendAPI = DefaultFrontendAPI.replace('[projectID]', projectID);
this.JWTIssuer = `${DefaultFrontendAPI.replace('[projectID]', projectID)}/.well-known/jwks`;
this.JWKSCache = DefaultJwksCache;
}

public setFrontendAPI(frontendApi: string): void {
Expand All @@ -75,11 +67,6 @@ class Config implements ConfigInterface {
this.Client = client;
}

public setJwksCache(jwksCache: MemoryCache<string, string>): void {
Assert.notNull(jwksCache, 'JWKS cache');
this.JWKSCache = jwksCache;
}

private validateProjectID(projectID: string): void {
if (!projectID || !projectID.startsWith('pro-')) {
throw new Error('ProjectID must not be empty and must start with "pro-".');
Expand Down
3 changes: 1 addition & 2 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class SDK {
this.axiosClient,
config.ShortSessionCookieName,
config.FrontendAPI,
config.JWTIssuer,
config.JWKSCache,
config.FrontendAPI + '/.well-known/jwks',
);

this.smsOTP = new SmsOTP(this.axiosClient);
Expand Down
4 changes: 0 additions & 4 deletions src/services/sessionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class Session implements SessionInterface {

private jwksURI: string;

private jwksCache: MemoryCache<string, string>;

private cacheMaxAge: number;

private lastShortSessionValidationResult: string = '';
Expand All @@ -54,7 +52,6 @@ class Session implements SessionInterface {
shortSessionCookieName: string,
issuer: string,
jwksURI: string,
jwksCache = new MemoryCache<string, string>(itemsExpirationCheckIntervalInSecs, maxItemCount),
cacheMaxAge = 10 * 60, // 10 minutes
) {
if (!shortSessionCookieName || !issuer || !jwksURI) {
Expand All @@ -65,7 +62,6 @@ class Session implements SessionInterface {
this.shortSessionCookieName = shortSessionCookieName;
this.issuer = issuer;
this.jwksURI = jwksURI;
this.jwksCache = jwksCache;
this.cacheMaxAge = cacheMaxAge;
}

Expand Down
3 changes: 0 additions & 3 deletions tests/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ describe('Configuration class', () => {
expect(config.BackendAPI).toBe(DefaultBackendAPI);
expect(config.ShortSessionCookieName).toBe(DefaultShortSessionCookieName);
expect(config.CacheMaxAge).toBe(DefaultCacheMaxAge);
expect(config.JWTIssuer).toBe(`https://${projectID}.frontendapi.corbado.io/.well-known/jwks`);
expect(config.JWKSCache).toBe(DefaultJwksCache);
};

it('should instantiate Configuration with valid project ID and API secret', () => {
Expand All @@ -40,7 +38,6 @@ describe('Configuration class', () => {
expect(config.BackendAPI).toBe(DefaultBackendAPI);
expect(config.ShortSessionCookieName).toBe(DefaultShortSessionCookieName);
expect(config.CacheMaxAge).toBe(DefaultCacheMaxAge);
expect(config.JWTIssuer).toBe(`https://${projectID}.frontendapi.corbado.io/.well-known/jwks`);
});

it('should generate DefaultFrontendAPI using process.env.CORBADO_PROJECT_ID and provided project ID', () => {
Expand Down
7 changes: 1 addition & 6 deletions tests/unit/services/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ describe('Session', () => {
issuer = Utils.testConstants.TEST_REDIRECT_URL;
shortSessionCookieName = 'session';
jwksURI = `${Utils.testConstants.TEST_REDIRECT_URL}/jwks`;
jwksCache = new MemoryCache<string, string>(1, 100);
createSession = () =>
new Session(Utils.MockAxiosInstance().axiosInstance, shortSessionCookieName, issuer, jwksURI, jwksCache);
});

afterAll(() => {
jwksCache.destroy();
new Session(Utils.MockAxiosInstance().axiosInstance, shortSessionCookieName, issuer, jwksURI);
});

it('should create a Session instance with valid parameters', () => {
Expand Down

0 comments on commit b164682

Please sign in to comment.