Skip to content

Free the business code from the token argument. - #7

Open
e-gautier wants to merge 2 commits into
tduboys:mainfrom
e-gautier:session
Open

Free the business code from the token argument.#7
e-gautier wants to merge 2 commits into
tduboys:mainfrom
e-gautier:session

Conversation

@e-gautier

Copy link
Copy Markdown
Contributor

Simplify the code in order to introduce new features.

@tduboys

tduboys commented Nov 15, 2022

Copy link
Copy Markdown
Owner

it will probably breaks moffics.py too

@tduboys

tduboys commented Nov 20, 2022

Copy link
Copy Markdown
Owner

Seems good, but just to be safe, maybe add a before_request method that resets session token, as it's the same session object in every http query

something like : (i dont know how to add suggested patch on pr… :/ )

diff --git a/moffics.py b/moffics.py
index d373ec6..261c7f9 100755
--- a/moffics.py
+++ b/moffics.py
@@ -136,6 +136,12 @@ def get_with_token(token: str):
 
     return get_ics_from_moffi()
 
+def reset_session():
+    """
+    Reset session token, to be safe
+    """
+    APP.logger.debug("Reset session token")
+    session.TOKEN = None
 
 if __name__ == "__main__":
 
@@ -168,4 +174,5 @@ if __name__ == "__main__":
             sys.exit(1)
         APP.config["secret_key"] = CONF.get("secret").encode("utf-8")
 
+    APP.before_request(reset_session)
     APP.run(host=CONF.get("listen"), port=CONF.get("port"), debug=CONF.get("verbose"))

@tduboys tduboys left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

pylint review

Comment thread moffi_sdk/auth.py Outdated

Raise AuthenticationException in case of error
"""
TOKEN: str

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

moffi_sdk/auth.py:37:8: C0103: Attribute name "TOKEN" doesn't conform to snake_case naming style (invalid-name)

@e-gautier

Copy link
Copy Markdown
Contributor Author

The best way would be to authenticate and create the session on server start and actually use the same token right?

@tduboys

tduboys commented Nov 20, 2022

Copy link
Copy Markdown
Owner

The best way would be to authenticate and create the session on server start and actually use the same token right?

probably not, for 2 reasons

  • I suppose the session token have a time limit
  • One server can handle multiple clients with different accounts, every client have this own login and token

I suggest to re-signing on every request
It takes times, but calendar client will do 1 request every X hours, it's not too frequent

@e-gautier

Copy link
Copy Markdown
Contributor Author

The signin method will reset the token on each request but I get your point. I will seek for a better solution.

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.

2 participants