PR feedback

This commit is contained in:
Tom Moor committed 2025-04-22 21:19:16 -04:00
1 parent 20f5e953b7
commit bee61ce1ef
5 files changed
+23 -4

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ export class OAuthScopeHelper {
create: t("write"),
update: t("write"),
delete: t("write"),
"*": t("manage"),
"*": t("read and write"),
};
const translatedNamespaces = {
@@ -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<OAuthAuthentication>,
Partial<InferCreationAttributes<OAuthAuthentication>>
> {
/** 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
@@ -26,6 +26,10 @@ class OAuthAuthorizationCode extends IdModel<
InferAttributes<OAuthAuthorizationCode>,
Partial<InferCreationAttributes<OAuthAuthorizationCode>>
> {
/** The lifetime of an authorization code in seconds. */
public static authorizationCodeLifetime = 300;
/** A recognizable prefix for authorization codes. */
public static authorizationCodePrefix = "ol_ac_";
@Column
+7 -2
View File
@@ -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);
+1 -1
View File
@@ -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",