From bee61ce1ef7fa6b7e18b0b245cc555fa0e1ff52b Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 22 Apr 2025 21:19:16 -0400 Subject: [PATCH] PR feedback --- app/scenes/Login/OAuthScopeHelper.ts | 2 +- server/models/oauth/OAuthAuthentication.ts | 10 ++++++++++ server/models/oauth/OAuthAuthorizationCode.ts | 4 ++++ server/routes/oauth/index.ts | 9 +++++++-- shared/i18n/locales/en_US/translation.json | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/scenes/Login/OAuthScopeHelper.ts b/app/scenes/Login/OAuthScopeHelper.ts index 19a366bb96..598d4ef004 100644 --- a/app/scenes/Login/OAuthScopeHelper.ts +++ b/app/scenes/Login/OAuthScopeHelper.ts @@ -13,7 +13,7 @@ export class OAuthScopeHelper { create: t("write"), update: t("write"), delete: t("write"), - "*": t("manage"), + "*": t("read and write"), }; const translatedNamespaces = { diff --git a/server/models/oauth/OAuthAuthentication.ts b/server/models/oauth/OAuthAuthentication.ts index dabf3b8c0b..e726c56948 100644 --- a/server/models/oauth/OAuthAuthentication.ts +++ b/server/models/oauth/OAuthAuthentication.ts @@ -16,6 +16,7 @@ import { IsDate, Unique, } from "sequelize-typescript"; +import { Day, Hour } from "@shared/utils/time"; import User from "@server/models/User"; import ParanoidModel from "@server/models/base/ParanoidModel"; import { SkipChangeset } from "@server/models/decorators/Changeset"; @@ -33,7 +34,16 @@ class OAuthAuthentication extends ParanoidModel< InferAttributes, Partial> > { + /** The lifetime of an access token in seconds. */ + public static accessTokenLifetime = Hour.seconds; + + /** The lifetime of a refresh token in seconds. */ + public static refreshTokenLifetime = 30 * Day.seconds; + + /** A recognizable prefix for access tokens. */ public static accessTokenPrefix = "ol_at_"; + + /** A recognizable prefix for refresh tokens. */ public static refreshTokenPrefix = "ol_rt_"; @Unique diff --git a/server/models/oauth/OAuthAuthorizationCode.ts b/server/models/oauth/OAuthAuthorizationCode.ts index 5af6e2b20d..b56e8a0a0b 100644 --- a/server/models/oauth/OAuthAuthorizationCode.ts +++ b/server/models/oauth/OAuthAuthorizationCode.ts @@ -26,6 +26,10 @@ class OAuthAuthorizationCode extends IdModel< InferAttributes, Partial> > { + /** The lifetime of an authorization code in seconds. */ + public static authorizationCodeLifetime = 300; + + /** A recognizable prefix for authorization codes. */ public static authorizationCodePrefix = "ol_ac_"; @Column diff --git a/server/routes/oauth/index.ts b/server/routes/oauth/index.ts index cf1a9460f9..d5a919ce99 100644 --- a/server/routes/oauth/index.ts +++ b/server/routes/oauth/index.ts @@ -8,7 +8,7 @@ import { rateLimiter } from "@server/middlewares/rateLimiter"; import requestTracer from "@server/middlewares/requestTracer"; import { transaction } from "@server/middlewares/transaction"; import validate from "@server/middlewares/validate"; -import { OAuthClient } from "@server/models"; +import { OAuthAuthorizationCode, OAuthClient } from "@server/models"; import OAuthAuthentication from "@server/models/oauth/OAuthAuthentication"; import { authorize } from "@server/policies"; import { APIContext } from "@server/types"; @@ -43,6 +43,8 @@ router.post( const authorizationCode = await oauth.authorize(request, response, { allowEmptyState: true, + authorizationCodeLifetime: + OAuthAuthorizationCode.authorizationCodeLifetime, authenticateHandler: { // Fetch the current user from the request, so the library knows // which user is authorizing the client. @@ -68,7 +70,10 @@ router.post("/token", async (ctx) => { // Note: These objects are mutated by the OAuth2Server library const request = new OAuth2Server.Request(ctx.request); const response = new OAuth2Server.Response(ctx.response); - const token = await oauth.token(request, response); + const token = await oauth.token(request, response, { + accessTokenLifetime: OAuthAuthentication.accessTokenLifetime, + refreshTokenLifetime: OAuthAuthentication.refreshTokenLifetime, + }); if (response.headers) { ctx.set(response.headers); diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 383d56e123..6aab702c08 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -839,7 +839,7 @@ "{{ appName }} will be able to access your account and perform the following actions": "{{ appName }} will be able to access your account and perform the following actions", "read": "read", "write": "write", - "manage": "manage", + "read and write": "read and write", "API keys": "API keys", "attachments": "attachments", "collections": "collections",