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

Regression: UIKit buttons auth user validation #26171

Merged
merged 4 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 4 additions & 4 deletions apps/meteor/app/api/server/middlewares/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ export function authenticationMiddleware(config: AuthenticationMiddlewareConfig
const { 'x-user-id': userId, 'x-auth-token': authToken } = req.headers;

if (userId && authToken) {
req.body.user = Users.findOneByIdAndLoginToken(userId, authToken);
req.user = Users.findOneByIdAndLoginToken(userId, authToken);
} else {
req.body.user = oAuth2ServerAuth(req)?.user;
req.user = oAuth2ServerAuth(req)?.user;
}

if (config.rejectUnauthorized && !req.body.user) {
if (config.rejectUnauthorized && !req.user) {
res.status(401).send('Unauthorized');
return;
}

req.userId = req.body?.user?._id;
req.userId = req?.user?._id;

next();
};
Expand Down
12 changes: 6 additions & 6 deletions apps/meteor/app/apps/server/communication/uikit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ Meteor.startup(() => {

router.use(authenticationMiddleware({ rejectUnauthorized: false }));

router.use((req, res, next) => {
router.use((req: Request, res, next) => {
const { 'x-visitor-token': visitorToken } = req.headers;

if (visitorToken) {
req.body.visitor = Apps.getConverters()?.get('visitors').convertByToken(visitorToken);
}

if (!req.body.user && !req.body.visitor) {
if (!req.user && !req.body.visitor) {
return unauthorized(res);
}

Expand Down Expand Up @@ -186,7 +186,7 @@ const appsRoutes =

const { visitor } = req.body;
const room = orch.getConverters()?.get('rooms').convertById(rid);
const user = orch.getConverters()?.get('users').convertToApp(req.body.user);
const user = orch.getConverters()?.get('users').convertToApp(req.user);
const message = mid && orch.getConverters()?.get('messages').convertById(mid);

const action = {
Expand Down Expand Up @@ -221,7 +221,7 @@ const appsRoutes =
payload: { view, isCleared },
} = req.body;

const user = orch.getConverters()?.get('users').convertToApp(req.body.user);
const user = orch.getConverters()?.get('users').convertToApp(req.user);

const action = {
type,
Expand All @@ -247,7 +247,7 @@ const appsRoutes =
case UIKitIncomingInteractionType.VIEW_SUBMIT: {
const { type, actionId, triggerId, payload } = req.body;

const user = orch.getConverters()?.get('users').convertToApp(req.body.user);
const user = orch.getConverters()?.get('users').convertToApp(req.user);

const action = {
type,
Expand Down Expand Up @@ -279,7 +279,7 @@ const appsRoutes =
} = req.body;

const room = orch.getConverters()?.get('rooms').convertById(rid);
const user = orch.getConverters()?.get('users').convertToApp(req.body.user);
const user = orch.getConverters()?.get('users').convertToApp(req.user);
const message = mid && orch.getConverters()?.get('messages').convertById(mid);

const action = {
Expand Down