Skip to content

feat: authentication on all endpoints that interact with TeslaMate#352

Open
jlestel wants to merge 14 commits into
tobiasehlert:mainfrom
jlestel:main
Open

feat: authentication on all endpoints that interact with TeslaMate#352
jlestel wants to merge 14 commits into
tobiasehlert:mainfrom
jlestel:main

Conversation

@jlestel
Copy link
Copy Markdown
Contributor

@jlestel jlestel commented Sep 3, 2025

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

@jlestel jlestel mentioned this pull request Sep 3, 2025
@tobiasehlert tobiasehlert changed the title Authentication on all endpoints that interact with TeslaMate feat: authentication on all endpoints that interact with TeslaMate Sep 8, 2025
@tobiasehlert tobiasehlert added documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update Go code labels Sep 9, 2025
Copilot AI review requested due to automatic review settings October 6, 2025 18:39
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/v1_TeslaMateAPICarsDrives.go Outdated
Comment on lines +16 to +20

// authentication for the endpoint
validToken, errorMessage := validateAuthToken(c)
if !validToken {
TeslaMateAPIHandleErrorResponse(c, "TeslaMateAPICarsDrivesV1", CarsDrivesError2, errorMessage)
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using CarsDrivesError2 (Invalid date format) for authentication error is misleading. Should use CarsDrivesError1 (Unable to load drives) or create a specific authentication error message.

Suggested change
// 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)

Copilot uses AI. Check for mistakes.
Comment thread src/v1_TeslaMateAPICarsCharges.go Outdated
Comment on lines +16 to +20

// authentication for the endpoint
validToken, errorMessage := validateAuthToken(c)
if !validToken {
TeslaMateAPIHandleErrorResponse(c, "TeslaMateAPICarsChargesV1", CarsChargesError2, errorMessage)
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using CarsChargesError2 (Invalid date format) for authentication error is misleading. Should use CarsChargesError1 (Unable to load charges) or create a specific authentication error message.

Suggested change
// 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)

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

@jpizquierdo
Copy link
Copy Markdown

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

@gtrabanco
Copy link
Copy Markdown

Would be nice to merge this one, please @tobiasehlert

Copilot AI review requested due to automatic review settings January 18, 2026 23:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings January 18, 2026 23:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sonarqubecloud
Copy link
Copy Markdown

@jlestel
Copy link
Copy Markdown
Contributor Author

jlestel commented Mar 31, 2026

@tobiasehlert any throughs on it?

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants