Replace fosite with native OAuth implementation and quality fixes#40
Replace fosite with native OAuth implementation and quality fixes#40
Conversation
Replaces the fosite OAuth library with a native implementation that's simpler, has fewer dependencies, and gives us full control over the token flow. Also includes quality improvements found during review: - Fix SSE proxy content-type check to handle parameters (charset=utf-8) - Fix data race on package-level logger variable in log package - Deduplicate log level parsing and LogWithFields helpers - Change GenerateSecureToken to return error instead of empty string
Summary of ChangesHello @dgellow, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request undertakes a significant architectural shift by replacing the existing 'fosite' OAuth library with a custom-built native OAuth 2.0 implementation. This change aims to simplify the codebase, reduce external dependencies, and offer greater flexibility and control over the OAuth token lifecycle, including authorization code, access token, and refresh token flows. Complementing this core refactoring, several quality improvements were integrated, addressing a data race in the logging system, refining log level parsing, enhancing secure token generation with explicit error handling, and fixing a content-type parsing issue in the SSE proxy. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request is a major and impressive refactoring that replaces the fosite OAuth library with a simpler, native implementation. This gives the project more control and reduces dependencies significantly. The new implementation is well-structured, with clear separation of concerns and a comprehensive test suite that provides confidence in its correctness.
In addition to the OAuth replacement, this PR includes several valuable quality improvements:
- A fix for a data race in the logging package by removing a global logger variable.
- Deduplication of logging logic, improving maintainability.
- A more robust SSE content-type check.
- Improved error handling in
GenerateSecureTokenby returning an error instead of an empty string.
The overall quality of the changes is very high. I have one suggestion for improvement in internal/storage/memory.go regarding session cleanup when a user is deleted.
| func (s *MemoryStorage) DeleteUser(ctx context.Context, email string) error { | ||
| s.usersMutex.Lock() | ||
| defer s.usersMutex.Unlock() | ||
|
|
||
| delete(s.users, email) | ||
|
|
||
| // Also delete all user tokens | ||
| s.userTokensMutex.Lock() | ||
| defer s.userTokensMutex.Unlock() | ||
|
|
||
| prefix := email + ":" | ||
| for key := range s.userTokens { | ||
| if strings.HasPrefix(key, prefix) { | ||
| delete(s.userTokens, key) | ||
| } | ||
| } | ||
| s.userTokensMutex.Unlock() | ||
|
|
||
| s.usersMutex.Lock() | ||
| delete(s.users, email) | ||
| s.usersMutex.Unlock() | ||
|
|
||
| return nil | ||
| } |
There was a problem hiding this comment.
The DeleteUser function successfully removes the user and their associated tokens, but it overlooks revoking the user's active sessions. This could leave orphaned sessions that remain active until they expire, which might be a security concern. It would be more robust to also iterate through active sessions and remove any belonging to the deleted user.
func (s *MemoryStorage) DeleteUser(ctx context.Context, email string) error {
s.userTokensMutex.Lock()
prefix := email + ":"
for key := range s.userTokens {
if strings.HasPrefix(key, prefix) {
delete(s.userTokens, key)
}
}
s.userTokensMutex.Unlock()
s.sessionsMutex.Lock()
for id, session := range s.sessions {
if session.UserEmail == email {
delete(s.sessions, id)
}
}
s.sessionsMutex.Unlock()
s.usersMutex.Lock()
delete(s.users, email)
s.usersMutex.Unlock()
return nil
}
Replaces the fosite OAuth library with a native implementation that's simpler, has fewer dependencies, and gives us full control over the token flow. Also includes quality improvements found during review: