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

WebApi of remote start, remote stop and connector status #1291

Open
wants to merge 58 commits into
base: master
Choose a base branch
from

Conversation

fnkbsi
Copy link
Contributor

@fnkbsi fnkbsi commented Nov 6, 2023

Adding a Webapi for RemoteStart, RemoteStop and Connector Status. The RestApi behaves similarly to the website. RemoteStart and RemoteStop respond with the task ID that can be used to check the result of TransactionStart/TransactionStop.

Tester and others added 29 commits October 20, 2023 10:49
…geBoxId, Integer connectorId) and getOcppTagOfTransaction(Integer transaction_pk);
…tor for RemoteStart, RemoteStop and UnlockConnector
…ere is already a active transaction, methode postUnlockCon checks no that there is no active transaction, removed the ocpp tag check; Added comments
@juherr juherr mentioned this pull request Nov 6, 2023
37 tasks
@juherr
Copy link
Contributor

juherr commented Jun 19, 2024

@goekay Please review, this PR is improving the product.

Copy link
Contributor

@dakai-wei-of-shizen dakai-wei-of-shizen 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
I merged this in my forked repo and it worked fine.

@juherr Thx!!!!!!!

@JocelynMeyron-eaton
Copy link

@goekay @fnkbsi Thanks for the huge work! I just had one question: any plan on merging this PR?

@navaneethred
Copy link

Hey, can anybody please tell me how to use the APIs. I have got steve with your modifications running, but I cannot for the love of god get any API responses.
image

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Oct 7, 2024

Hey, can anybody please tell me how to use the APIs. I have got steve with your modifications running, but I cannot for the love of god get any API responses.

set the api-key in the config file
recompile and restart steve
add the api-key "STEVE-API-KEY" (with the value of the config) to the header of our request

@navaneethred
Copy link

Did all that still gives the same error.
image
image

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Oct 7, 2024

Did all that still gives the same error.

steve changed to basic auth for the api.
add a api_password to the web_user in the database and try again with basic authentication.
There is no website for setting the api_password, so you have to set it otherwise.

I haven't test it with the basic auth! There may be more problems.

@navaneethred
Copy link

Yeah that worked. Thank you so much.

@LydiaBenaida
Copy link

Hello,
i'm workking with API, we did notice the change from key value to basic auth,
my question is : what is the role of pasword api ? the key value is stored as password api
BUT for me when in debug mode it compares the password api i m using with the normal password ,
i dont know exactly how the key value (password api) can be used

thank you

` @OverRide
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = (String) authentication.getPrincipal();
String apiPassword = (String) authentication.getCredentials();

    if (Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(apiPassword)) {
        throw new BadCredentialsException("Required parameters missing");
    }

    UserDetails userDetails = webUserService.loadUserByUsernameForApi(username);
    if (!areValuesSet(userDetails)) {
        throw new DisabledException("The user does not exist, exists but is disabled or has API access disabled.");
    }

    **boolean match = passwordEncoder.matches(apiPassword, userDetails.getPassword());**
    if (!match) {
        throw new BadCredentialsException("Invalid password");
    }

    return UsernamePasswordAuthenticationToken.authenticated(
            authentication.getPrincipal(),
            authentication.getCredentials(),
            userDetails.getAuthorities()
    );
}`

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Nov 8, 2024

` @OverRide public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = (String) authentication.getPrincipal(); String apiPassword = (String) authentication.getCredentials();

    if (Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(apiPassword)) {
        throw new BadCredentialsException("Required parameters missing");
    }

    UserDetails userDetails = webUserService.loadUserByUsernameForApi(username);
    if (!areValuesSet(userDetails)) {
        throw new DisabledException("The user does not exist, exists but is disabled or has API access disabled.");
    }

    **boolean match = passwordEncoder.matches(apiPassword, userDetails.getPassword());**
    if (!match) {
        throw new BadCredentialsException("Invalid password");
    }

    return UsernamePasswordAuthenticationToken.authenticated(
            authentication.getPrincipal(),
            authentication.getCredentials(),
            userDetails.getAuthorities()
    );
}`

In the discussion of "switch to basic auth for API access #1545" is the role and background for the change already addressed.

In the appended code it only seems that the api-password is checked against the password. webUserService.loadUserByUsernameForApi reads the api-password from the database and stores it as 'password' in userDetails (just (re)using the existing class)

If you working with a existing database, please check if Steve had ported the api-key into the web-user api-password.

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.

7 participants