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

Revert auth changes due to rollback #136

Merged
merged 4 commits into from
Apr 24, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Removed
- Reverted changes from versions 1.40.3, 1.40.2 and 1.40.1

## [1.40.3] - 2024-04-24

### Fixed
Expand Down
15 changes: 5 additions & 10 deletions node/clients/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@ import { Schema } from './schema'
import VtexId from './vtexId'

export const getTokenToHeader = (ctx: IOContext) => {
const adminToken = ctx.adminUserAuthToken ?? ctx.authToken
const userToken = ctx.storeUserAuthToken ?? null
const { sessionToken, account } = ctx
const token =
ctx.storeUserAuthToken ?? ctx.adminUserAuthToken ?? ctx.authToken

let allCookies = `VtexIdclientAutCookie=${adminToken}`

if (userToken) {
allCookies += `; VtexIdclientAutCookie_${account}=${userToken}`
}
const { sessionToken } = ctx

return {
VtexIdclientAutCookie: adminToken,
cookie: allCookies,
VtexIdclientAutCookie: token,
cookie: `VtexIdclientAutCookie=${token}`,
'x-vtex-session': sessionToken ?? '',
}
}
Expand Down
11 changes: 1 addition & 10 deletions node/directives/checkAdminAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ export class CheckAdminAccess extends SchemaDirectiveVisitor {
}

try {
const authUser = await identity.validateToken({
token: adminUserAuthToken,
})

if (!authUser?.audience || authUser?.audience !== 'admin') {
logger.warn({
message: `CheckAdminAccess: No valid user found by admin token`,
})
throw new ForbiddenError('Unauthorized Access')
}
await identity.validateToken({ token: adminUserAuthToken })
} catch (err) {
logger.warn({
error: err,
Expand Down
28 changes: 1 addition & 27 deletions node/directives/checkUserAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import type { GraphQLField } from 'graphql'
import { defaultFieldResolver } from 'graphql'
import { SchemaDirectiveVisitor } from 'graphql-tools'

import { getActiveUserByEmail } from '../resolvers/Queries/Users'

export async function checkUserOrAdminTokenAccess(
ctx: Context,
operation?: string
Expand All @@ -24,17 +22,7 @@ export async function checkUserOrAdminTokenAccess(

if (adminUserAuthToken) {
try {
const authUser = await identity.validateToken({
token: adminUserAuthToken,
})

if (!authUser?.audience || authUser?.audience !== 'admin') {
logger.warn({
message: `CheckUserAccess: No valid user found by admin token`,
operation,
})
throw new ForbiddenError('Unauthorized Access')
}
await identity.validateToken({ token: adminUserAuthToken })
} catch (err) {
logger.warn({
error: err,
Expand All @@ -54,20 +42,6 @@ export async function checkUserOrAdminTokenAccess(
operation,
})
authUser = null
} else {
const user = (await getActiveUserByEmail(
null,
{ email: authUser?.user },
ctx
)) as { roleId: string } | null

if (!user?.roleId) {
logger.warn({
message: `CheckUserAccess: No valid role for user found by store user token`,
operation,
})
authUser = null
}
}
} catch (err) {
logger.warn({
Expand Down
Loading