Skip to content
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

switch to basic auth for API access #1545

Merged
merged 6 commits into from
Aug 21, 2024
Merged

Conversation

goekay
Copy link
Member

@goekay goekay commented Aug 17, 2024

No description provided.

@goekay goekay linked an issue Aug 17, 2024 that may be closed by this pull request
3 tasks
Copy link
Contributor

@juherr juherr left a comment

Choose a reason for hiding this comment

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

LGTM from a technical pov.
But why do you prefer basic auth instead of dedicated header or bearer token for api auth?

@goekay
Copy link
Member Author

goekay commented Aug 17, 2024

But why do you prefer basic auth instead of dedicated header or bearer token for api auth?

pls see #1540 (comment)

@@ -99,8 +113,19 @@ public void commence(HttpServletRequest request,
response.getWriter().print(jacksonObjectMapper.writeValueAsString(apiResponse));
}

private UserDetails getFromCacheOrDatabase(String username) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you set the cache logic here instead of webUserService.loadUserByUsernameForApi?

I don't know if it is a choice to not use it but Spring has its own way of doing caches: https://spring.io/guides/gs/caching
And you can still use guava under to wood if you want it: https://docs.spring.io/spring-framework/docs/4.2.x/javadoc-api/org/springframework/cache/guava/GuavaCacheManager.html

Copy link
Contributor

Choose a reason for hiding this comment

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

@goekay Just for my technical knowledge because I didn't use them before: why do you use guava directly and not hidden behind spring cache?

Copy link
Member Author

Choose a reason for hiding this comment

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

a combination of multiple reasons actually (disclaimer: i have been using both of them for a long time)

  • stylistic preference if it is just about a localized cache usage, instead of something big or application-wide
  • tighter control i can have with guava. this does not matter when using GuavaCacheManager, since the same can be done with that... but then, if you control guava like this, why introduce spring magic? which brings me to my next point.
  • absence of multiple spring layers, abstractions, which can lead to weird misbehaviour and gotchas
  • to be consistent with the codebase: steve has this direct usage of Guava at some other places, there is no usage of Spring cache

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the answer! 👍

why introduce spring magic?

That could be true for almost every spring import ;)

@goekay goekay marked this pull request as ready for review August 18, 2024 14:57
@goekay
Copy link
Member Author

goekay commented Aug 20, 2024

@juherr if you have no objections or no more comments, i want to merge this.

Copy link
Contributor

@juherr juherr left a comment

Choose a reason for hiding this comment

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

LGTM

@goekay goekay merged commit 4b63474 into master Aug 21, 2024
45 checks passed
@goekay goekay deleted the 1540-store-web-api-key-in-database branch August 21, 2024 06:56
@faculoyarte
Copy link

faculoyarte commented Aug 27, 2024

Sorry guys, but I'm having trouble figuring out how to create an api_password on a user or set up admin users in the SteVe web UI. I had the API working previously using webapi.key = STEVE-API-KEY and webapi.value, but now I'm getting a 401 error. Could someone guide me on how to resolve this?"
image

@goekay
Copy link
Member Author

goekay commented Aug 27, 2024

hey @faculoyarte, the user you are showing on the screenshot is the end user, i.e. the customer that has an EV and RFID card and wants to use the stations.

the user we added in this PR is the web user, i.e. the operations person that manages stations, someone that belongs to a CPO maybe. this is the person that has access to steve's web ui to do things. the web user gets an api_password with this PR.

therefore, these two things are disconnected. there is another PR that will make it available to update/change properties of a web user. therefore, currently the only way to do is to directly modify database tables.

@faculoyarte
Copy link

Perfect, thanks. @goekay

faculoyarte pushed a commit to faculoyarte/steve that referenced this pull request Sep 4, 2024
* switch to basic auth for API access

* PR feedback

* add cache for API users

* PR feedback

* start setting/updating api_password

* refactor: undo moveApiTokenFromConfigToDatabase prep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store Web API key in database -> Switch to basic auth
3 participants