mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-13 04:41:24 +00:00
Auto login on the SDK if local session is found (#4297)
* token generation on the terminal * revoke and show commands * auto login on the sdk if local session is found * fix tests --------- Co-authored-by: Luqman <luqazino@gmail.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
This commit is contained in:
@@ -22,6 +22,7 @@ from openbb_terminal.sdk_core import (
|
||||
)
|
||||
from openbb_terminal import feature_flags as obbff
|
||||
from openbb_terminal.session.user import User
|
||||
from openbb_terminal.terminal_helper import is_auth_enabled
|
||||
|
||||
if User.is_guest():
|
||||
load_dotenv_and_reload_configs()
|
||||
@@ -48,6 +49,14 @@ class OpenBBSDK:
|
||||
self.logout = lib.sdk_session.logout
|
||||
self.news = lib.common_feedparser_model.get_news
|
||||
self.whoami = lib.sdk_session.whoami
|
||||
self._try_to_login()
|
||||
|
||||
def _try_to_login(self):
|
||||
if User.is_guest() and is_auth_enabled():
|
||||
try:
|
||||
self.login()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@property
|
||||
def alt(self):
|
||||
|
||||
@@ -18,7 +18,7 @@ def get_session(email: str, password: str, token: str, save: bool):
|
||||
console.print("Creating session from token.")
|
||||
session = session_model.create_session_from_token(token, save) # type: ignore
|
||||
|
||||
if not session:
|
||||
if not session and email:
|
||||
console.print("Creating session from email and password.")
|
||||
session = session_model.create_session(email, password, save) # type: ignore
|
||||
|
||||
@@ -55,11 +55,10 @@ def login(
|
||||
>>> from openbb_terminal.sdk import openbb
|
||||
>>> openbb.login(email="your_email", password="your_password")
|
||||
"""
|
||||
|
||||
session = Local.get_session()
|
||||
if not (email or token):
|
||||
session = Local.get_session()
|
||||
|
||||
if not session:
|
||||
console.print("No local session found. Creating new session.")
|
||||
session = get_session(email, password, token, keep_session)
|
||||
else:
|
||||
console.print("Using local session to login.")
|
||||
|
||||
Reference in New Issue
Block a user