Skip to content

Commit 03f842b

Browse files
📝 Add docstrings to fix/third-party-login
Docstrings generation was requested by @d-gubert. * #37707 (comment) The following files were modified: * `apps/meteor/app/api/server/middlewares/authentication.ts` * `apps/meteor/app/oauth2-server-config/server/oauth/oauth2-server.ts`
1 parent 06b4036 commit 03f842b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

apps/meteor/app/api/server/middlewares/authentication.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ type AuthenticationMiddlewareConfig = {
1010
cookies?: boolean;
1111
};
1212

13+
/**
14+
* Creates an Express middleware that authenticates requests using header/cookie tokens or OAuth2.
15+
*
16+
* The middleware sets `req.user` when authentication succeeds and `req.userId` to the authenticated user's `_id`.
17+
* If `rejectUnauthorized` is true and no user is authenticated, the middleware responds with HTTP 401 and stops the request.
18+
*
19+
* @param config - Configuration for the middleware.
20+
* - `rejectUnauthorized` (default: `true`): If true, unauthenticated requests are rejected with HTTP 401.
21+
* - `cookies` (default: `false`): If true, authentication values are read from cookies when available.
22+
* @returns An Express middleware function that enforces authentication and populates `req.user` and `req.userId`.
23+
*/
1324
export function authenticationMiddleware(
1425
config: AuthenticationMiddlewareConfig = {
1526
rejectUnauthorized: true,
@@ -69,4 +80,4 @@ export function hasPermissionMiddleware(
6980
}
7081
next();
7182
};
72-
}
83+
}

apps/meteor/app/oauth2-server-config/server/oauth/oauth2-server.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,21 @@ const oauth2server = new OAuth2Server({
1313
debug: false,
1414
});
1515

16-
// https://github.com/RocketChat/rocketchat-oauth2-server/blob/e758fd7ef69348c7ceceabe241747a986c32d036/model.coffee#L27-L27
16+
/**
17+
* Fetches an access token record by its token string.
18+
*
19+
* @returns The access token record matching `accessToken`, or `undefined` if none is found.
20+
*/
1721
async function getAccessToken(accessToken: string) {
1822
return OAuthAccessTokens.findOneByAccessToken(accessToken);
1923
}
2024

25+
/**
26+
* Authenticate a request using an OAuth2 access token and return the corresponding user.
27+
*
28+
* @param partialRequest - Object containing `headers` and `query` used to locate the access token (`Authorization: Bearer <token>` header or `access_token` query parameter)
29+
* @returns The authenticated `IUser` when the token is present, valid, and maps to an existing user; `undefined` if the token is missing, invalid, expired, or the user is not found
30+
*/
2131
export async function oAuth2ServerAuth(partialRequest: {
2232
headers: Record<string, string | undefined>;
2333
query: Record<string, string | undefined>;
@@ -82,4 +92,4 @@ API.v1.addAuthMethod((request: globalThis.Request) => {
8292
return oAuth2ServerAuth({ headers, query });
8393
});
8494

85-
(WebApp.connectHandlers as unknown as ReturnType<typeof express>).use(oauth2server.app);
95+
(WebApp.connectHandlers as unknown as ReturnType<typeof express>).use(oauth2server.app);

0 commit comments

Comments
 (0)