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

Added the ability to log in when using one time passwords. #13

Merged
merged 3 commits into from
Dec 19, 2020
Merged

Added the ability to log in when using one time passwords. #13

merged 3 commits into from
Dec 19, 2020

Conversation

danielvandenberg95
Copy link
Collaborator

No description provided.

@danielvandenberg95
Copy link
Collaborator Author

I forgot to compile, so please use squash commit to complete this PR in one commit.

Copy link
Owner

@icastillejogomez icastillejogomez left a comment

Choose a reason for hiding this comment

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

Hello Daniel!!

First pull the last changes of master branch.
Your changes break one login test
Provide a new custom test for your new awesome feature please to ensure this lib always works
After that I will merge your pull request for sure!

Thank you

@@ -44,12 +45,17 @@ export function loginRequest(params: LoginRequestParamsType): Promise<LoginRespo
debug(`Making request to ${BASE_API_URL + LOGIN_URL_PATH} with options:`)
debug(JSON.stringify(requestOptions, null, 2))
fetch(BASE_API_URL + LOGIN_URL_PATH, requestOptions)
.then((res) => {
if (!payload.oneTimePassword) return res
Copy link
Owner

Choose a reason for hiding this comment

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

I think this could be a break point because res is not a promise that is going to be result so the next then step maybe is not going to be triggered never??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It should not be, but I'll test it out.

Hello Daniel!!

First pull the last changes of master branch.
Your changes break one login test
Provide a new custom test for your new awesome feature please to ensure this lib always works
After that I will merge your pull request for sure!

Thank you

Unfortunately tests do not work out of the box. What I still had to do to get them working:

  • npm i -g mocha ts-node
  • I had to install something else but unfortunately I forgot what it was.

Returning from within a .then() should always allow the chain to continue.

Once I got the tests working, unfortunately my account got blocked. Reason being that a one time password can be used only once, and the tests fire numerous times with the same OTP. To make this work, the tests should only log in once, and then reuse that session. For tests like the logout, it should then prompt for a new OTP.

For now, once I get my account reactivated, I will be suspending my own testing, and simply keep using my own fork, as that one does work for me.

src/DeGiro.ts Outdated
@@ -101,7 +104,7 @@ export class DeGiro implements DeGiroClassInterface {
login(): Promise<AccountDataType> {
if (this.jsessionId) return this.loginWithJSESSIONID(this.jsessionId)
return new Promise((resolve, reject) => {
loginRequest({ username: this.username, pwd: this.pwd })
loginRequest({ username: this.username, pwd: this.pwd, oneTimePassword: this.oneTimePassword })
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe should put in 3 new lines instead of once

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, resolved in upcoming commit.

@icastillejogomez
Copy link
Owner

Okay, you are right. Re-use session on test set is a great nice-to-have. I'm going to merge your code and check if pass the tests with my account that has not OTP.

Good job and thank you!

@icastillejogomez icastillejogomez merged commit d5eb120 into icastillejogomez:master Dec 19, 2020
@arendjr
Copy link

arendjr commented Dec 29, 2020

Why do you perform two requests with OTP -- first the one without the OTP, followed by the one with OTP? It appears sending the one with OTP directly works as well.

@icastillejogomez
Copy link
Owner

Could be a great pull requests! You're right!

@arendjr
Copy link

arendjr commented Dec 30, 2020

Hi, I won't be creating PRs as I'm working on a competing implementation (WIP for Rust), but I'm happy to share my findings as I go along :)

On that note, from my testing, it appears the Referer header and the isPassCodeReset, isRedirectToMobile and queryParams properties shouldn't be necessary.

Would you like me to file issues whenever I stumble upon things?

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.

3 participants