-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: main
Are you sure you want to change the base?
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
@@ -104,7 +105,7 @@ export class JwtAuthStrategy extends PassportStrategy(Strategy, 'jwt') { | |||
} | |||
} | |||
|
|||
if (payload.workspaceId) { | |||
if (payload.type !== 'API_KEY') { |
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.
logic: Type check could allow null values through. Consider explicit check for type === 'API_KEY' instead.
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()
TODOs/FIXMEs:
|
Fix done this morning with @FelixMalfait from #8295