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 62 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.

@agent87
Copy link

agent87 commented Dec 3, 2024

ApiRemoteStartError

While posting a remoteStart at
{{baseUrl}}/api/v1/remote/start?chargeBoxId=0284085&connectorId=1&ocppTag=4853647

i am getting an internal server error 500 with the following verbose
{
"timestamp": "2024-12-03T05:27:10.102Z",
"status": 500,
"error": "Internal Server Error",
"message": "Cannot resolve parameter names for constructor public de.rwth.idsg.steve.web.api.dto.ApiChargePointStart(java.lang.String,java.lang.Integer,java.lang.String)",
"path": "http://evstaging.meshpower.co.rw:8180/steve/api/v1/remote/start"
}

The transaction is starting but i'm recieving an 500 internal server error response
image

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Dec 3, 2024

@agent87: thanks for the find. Please checkout the new commit 47b5784

@agent87
Copy link

agent87 commented Dec 5, 2024

@agent87: thanks for the find. Please checkout the new commit 47b5784

Thank you !

@agent87
Copy link

agent87 commented Dec 6, 2024

@agent87: thanks for the find. Please checkout the new commit 47b5784

Thank you !

@agent87: thanks for the find. Please checkout the new commit 47b5784

Another bug on the task, I am unable to retrieve a specific task id
image

Please check and let me know

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Dec 6, 2024

@agent87 let me know when you find more!

@agent87
Copy link

agent87 commented Dec 9, 2024

@agent87 let me know when you find more!
Another request, is it would be awesome to have meter readdings while accessing the transacion, i.e total kwh, power etc, is it something that can be added?

Great work by the way!

@fnkbsi
Copy link
Contributor Author

fnkbsi commented Dec 20, 2024

@agent87 let me know when you find more!
Another request, is it would be awesome to have meter readdings while accessing the transacion, i.e total kwh, power etc, is it something that can be added?

Great work by the way!

You mean something like at /transactions/details/{transactionPk}? (Prototype see https://github.com/fnkbsi/steve/tree/ApiTransactionDetails)

@agent87
Copy link

agent87 commented Dec 24, 2024

Okay I will check it out.
Also, I noticed you merged the master head commit, does it mean that this remoteStart feature is compatible with the latest steve version on the master branch?

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.

8 participants