feat: authentication on all endpoints that interact with TeslaMate#352
feat: authentication on all endpoints that interact with TeslaMate#352jlestel wants to merge 14 commits into
Conversation
|
There was a problem hiding this comment.
Pull Request Overview
This PR implements authentication on all TeslaMate API endpoints to avoid misconfigurations by requiring token validation for all data access operations.
- Added authentication checks to all TeslaMate API endpoints using
validateAuthToken() - Fixed duplicate authentication logic in the logging endpoint
- Updated documentation to reflect that all endpoints now require authentication
Reviewed Changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/v1_TeslaMateAPIGlobalsettings.go | Added authentication check before database operations |
| src/v1_TeslaMateAPICarsUpdates.go | Added authentication check at function start |
| src/v1_TeslaMateAPICarsLogging.go | Fixed duplicate authentication by reusing variables |
| src/v1_TeslaMateAPICarsDrivesDetails.go | Added authentication check before parameter processing |
| src/v1_TeslaMateAPICarsDrives.go | Added authentication check before parameter processing |
| src/v1_TeslaMateAPICarsChargesDetails.go | Added authentication check before parameter processing |
| src/v1_TeslaMateAPICarsCharges.go | Added authentication check before parameter processing |
| src/v1_TeslaMateAPICars.go | Added authentication check before database operations |
| README.md | Updated documentation to reflect authentication requirement for all endpoints |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| // authentication for the endpoint | ||
| validToken, errorMessage := validateAuthToken(c) | ||
| if !validToken { | ||
| TeslaMateAPIHandleErrorResponse(c, "TeslaMateAPICarsDrivesV1", CarsDrivesError2, errorMessage) |
There was a problem hiding this comment.
Using CarsDrivesError2 (Invalid date format) for authentication error is misleading. Should use CarsDrivesError1 (Unable to load drives) or create a specific authentication error message.
| // authentication for the endpoint | |
| validToken, errorMessage := validateAuthToken(c) | |
| if !validToken { | |
| TeslaMateAPIHandleErrorResponse(c, "TeslaMateAPICarsDrivesV1", CarsDrivesError2, errorMessage) | |
| var CarsDrivesErrorAuth = "Authentication failed." | |
| // authentication for the endpoint | |
| validToken, errorMessage := validateAuthToken(c) | |
| if !validToken { | |
| TeslaMateAPIHandleErrorResponse(c, "TeslaMateAPICarsDrivesV1", CarsDrivesErrorAuth, errorMessage) |
|
|
||
| // authentication for the endpoint | ||
| validToken, errorMessage := validateAuthToken(c) | ||
| if !validToken { | ||
| TeslaMateAPIHandleErrorResponse(c, "TeslaMateAPICarsChargesV1", CarsChargesError2, errorMessage) |
There was a problem hiding this comment.
Using CarsChargesError2 (Invalid date format) for authentication error is misleading. Should use CarsChargesError1 (Unable to load charges) or create a specific authentication error message.
| // authentication for the endpoint | |
| validToken, errorMessage := validateAuthToken(c) | |
| if !validToken { | |
| TeslaMateAPIHandleErrorResponse(c, "TeslaMateAPICarsChargesV1", CarsChargesError2, errorMessage) | |
| var CarsChargesAuthError = "Authentication failed." | |
| // authentication for the endpoint | |
| validToken, errorMessage := validateAuthToken(c) | |
| if !validToken { | |
| TeslaMateAPIHandleErrorResponse(c, "TeslaMateAPICarsChargesV1", CarsChargesAuthError, errorMessage) |
|
|
Did you find time to review the PR @tobiasehlert ? I think that it is a really interesting feature in order to intereact with the API securely |
|
Would be nice to merge this one, please @tobiasehlert |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/v1_TeslaMateAPICarsLogging.go:49
- This code now has duplicate authentication checks. The first authentication check is performed at lines 24-29, and then the same authentication check is performed again at lines 45-49. The second check (lines 45-49) should be removed as it is redundant and unreachable code - the function would have already returned at line 28 if authentication fails.
validToken, errorMessage = validateAuthToken(c)
if !validToken {
TeslaMateAPIHandleOtherResponse(c, http.StatusUnauthorized, "TeslaMateAPICarsLoggingV1", gin.H{"error": errorMessage})
return
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/v1_TeslaMateAPICarsLogging.go:49
- This function now has duplicate authentication checks. The first check at lines 24-29 will handle authentication for all requests (both GET and non-GET). The second authentication check at lines 44-49 is now redundant and should be removed since any request that reaches this point has already been authenticated.
validToken, errorMessage = validateAuthToken(c)
if !validToken {
TeslaMateAPIHandleOtherResponse(c, http.StatusUnauthorized, "TeslaMateAPICarsLoggingV1", gin.H{"error": errorMessage})
return
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
@tobiasehlert any throughs on it? |
|



To avoid misconfigurations, I suggest adding authentication on all endpoints.