-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix of broken API Auth #8338
Fix of broken API Auth #8338
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
This PR fixes API authentication for self-hosted instances by modifying the JWT payload structure and validation logic to properly handle API key tokens.
- Added
type: 'API_KEY'
field in JWT payload inpackages/twenty-server/src/engine/core-modules/auth/services/api-key.service.ts
to distinguish API tokens - Modified user lookup logic in
jwt.auth.strategy.ts
to skip user validation whenpayload.type === 'API_KEY'
- Updated token validation in
jwt.auth.strategy.ts
to properly handle API keys by checkingapiKey.revokedAt
status - Fixed workspace ID resolution by using
payload.workspaceId ?? payload.sub
for consistent workspace lookup
2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great first PR! 🙌
and refacto validate()
packages/twenty-server/src/engine/core-modules/auth/strategies/interfaces.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/strategies/interfaces.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.spec.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/auth/strategies/jwt.auth.strategy.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/environment/environment-variables.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/jwt/services/jwt-wrapper.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/jwt/services/jwt-wrapper.service.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/jwt/services/jwt-wrapper.service.ts
Outdated
Show resolved
Hide resolved
Thanks @guillim for your contribution! |
Fix done this morning with @FelixMalfait from #8295