Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrate more auth routes #1149

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@peculiar/x509": "^1.12.3",
"@planetscale/database": "1.19.0",
"arctic": "^2.3.0",
"authhero": "^0.20.2",
"authhero": "^0.21.0",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the results, I can generate the final response as we have enough information to verify the dependencies usage:

Dependencies removal needs additional changes

While the XML-related packages can be safely removed as XML processing is now handled by fast-xml-parser, the lru-cache package is still being used in src/middlewares/authentication.ts for JWKS key caching. Before removing lru-cache, you'll need to:

  • Replace the JWKS caching implementation in authentication.ts that currently uses LRUCache
  • Consider using a simpler caching mechanism or the new built-in Map with TTL implementation
🔗 Analysis chain

Verify removal of XML and caching dependencies

The removal of lru-cache, xml-crypto, and xmldsigjs dependencies aligns with the migration of auth routes. However, let's verify there are no remaining usages of these packages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify no remaining usage of removed dependencies

# Search for any remaining imports or requires of removed packages
echo "Checking for remaining imports..."
rg "require\(['\"](?:lru-cache|xml-crypto|xmldsigjs)['\"]" --type ts
rg "from ['\"](?:lru-cache|xml-crypto|xmldsigjs)['\"]" --type ts

# Search for XML-related code that might still need these dependencies
echo "Checking for XML-related code..."
rg "\.xml|XML|SAML" --type ts

# Search for caching-related code that might need lru-cache
echo "Checking for cache-related code..."
rg "cache|Cache" --type ts

Length of output: 26107

"bcryptjs": "^2.4.3",
"fast-xml-parser": "^4.5.0",
"hono": "4.4.0",
Expand All @@ -64,12 +64,9 @@
"kysely-bun-sqlite": "^0.3.2",
"kysely-planetscale": "^1.5.0",
"liquidjs": "^10.19.0",
"lru-cache": "^11.0.2",
"nanoid": "5.0.9",
"oslo": "^1.2.1",
"playwright": "1.44.1",
"xml-crypto": "^6.0.0",
"xmldsigjs": "^2.6.1",
"zod": "3.23.8"
},
"devDependencies": {
Expand Down
27 changes: 13 additions & 14 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
export const JWKS_CACHE_TIMEOUT_IN_SECONDS = 60 * 5; // 5 minutes
export const ACCESS_TOKEN_EXPIRE_IN_SECONDS = 60 * 60 * 24; // 24 hours
export const MONTH_IN_SECONDS = 30 * 24 * 60 * 60;

export const headers = {
accessControlAllowHeaders: "Access-Control-Allow-Headers",
accessControlAllowOrigin: "Access-Control-Allow-Origin",
accessControlAllowMethod: "Access-Control-Allow-Methods",
accessControlAllowCredentials: "Access-Control-Allow-Credentials",
accessControlExposeHeaders: "Access-Control-Expose-Headers",
cacheControl: "cache-control",
contentType: "content-type",
contentRange: "content-range",
location: "location",
setCookie: "set-cookie",
tenantId: "tenant-id",
};
// export const headers = {
// accessControlAllowHeaders: "Access-Control-Allow-Headers",
// accessControlAllowOrigin: "Access-Control-Allow-Origin",
// accessControlAllowMethod: "Access-Control-Allow-Methods",
// accessControlAllowCredentials: "Access-Control-Allow-Credentials",
// accessControlExposeHeaders: "Access-Control-Expose-Headers",
// cacheControl: "cache-control",
// contentType: "content-type",
// contentRange: "content-range",
// location: "location",
// setCookie: "set-cookie",
// tenantId: "tenant-id",
// };

export const UNIVERSAL_AUTH_SESSION_EXPIRES_IN_SECONDS = 60 * 60 * 24; // 1 day
export const OAUTH2_CODE_EXPIRES_IN_SECONDS = 5 * 60; // 5 minutes
Expand Down
10 changes: 1 addition & 9 deletions src/oauth-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ import { Env, Var } from "./types";
import { addDataHooks } from "./hooks";
import { CreateAuthParams } from "./app";
import { loginRoutes } from "./routes/universal-login/routes";
// import { wellKnownRoutes } from "./routes/oauth2/well-known";
import { authorizeRoutes } from "./routes/oauth2/authorize";
import { callbackRoutes } from "./routes/oauth2/callback";
import { userinfoRoutes } from "./routes/oauth2/userinfo";
// import { tokenRoutes } from "./routes/oauth2/token";
import { dbConnectionRoutes } from "./routes/oauth2/dbconnections";
import { passwordlessRoutes } from "./routes/oauth2/passwordless";
import { authenticateRoutes } from "./routes/oauth2/authenticate";
import { logoutRoutes } from "./routes/oauth2/logout";

export default function create(params: CreateAuthParams) {
const app = new OpenAPIHono<{ Bindings: Env; Variables: Var }>();
Expand All @@ -23,15 +19,11 @@ export default function create(params: CreateAuthParams) {

const oauthApp = app
.route("/u", loginRoutes)
// .route("/.well-known", wellKnownRoutes)
.route("/authorize", authorizeRoutes)
.route("/callback", callbackRoutes)
.route("/userinfo", userinfoRoutes)
// .route("/oauth/token", tokenRoutes)
.route("/dbconnections", dbConnectionRoutes)
.route("/passwordless", passwordlessRoutes)
.route("/co/authenticate", authenticateRoutes)
.route("/v2/logout", logoutRoutes);
.route("/co/authenticate", authenticateRoutes);

oauthApp.doc("/spec", {
openapi: "3.0.0",
Expand Down
88 changes: 0 additions & 88 deletions src/routes/oauth2/logout.ts

This file was deleted.

54 changes: 0 additions & 54 deletions src/routes/oauth2/userinfo.ts

This file was deleted.

116 changes: 0 additions & 116 deletions test/integration/flows/logout.spec.ts

This file was deleted.

Loading