Skip to content

Commit 579c6bd

Browse files
authored
Add device name tracking to browser login (#6)
* Add device name tracking to browser login * Update version and package initialization
1 parent e2c7a6e commit 579c6bd

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

smartloop/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21-
__version__="1.2.8"
21+
__version__="1.2.9"

smartloop/utils/browser_login.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import webbrowser
44
import threading
55
import uuid
6+
import socket
67
import logging
78
from urllib.parse import urlparse
89
import requests
@@ -15,6 +16,8 @@
1516
log = logging.getLogger('werkzeug')
1617
log.setLevel(logging.ERROR) # Hides most warnings
1718

19+
client_id = os.getenv('SLP_CLIENT_ID', f"smartloop-on-{socket.gethostname()}")
20+
1821
class BrowserLogin:
1922
'''Class to handle browser-based login for SmartLoop CLI.'''
2023
def __init__(self, port=5000):
@@ -113,7 +116,7 @@ def _exchange_code_for_token(self, code):
113116
'grant_type': 'authorization_code',
114117
'code': code,
115118
'redirect_uri': self.redirect_uri,
116-
'client_id': os.getenv('SLP_CLIENT_ID', 'smartloop-cli')
119+
'client_id': client_id
117120
}
118121
)
119122

@@ -149,7 +152,6 @@ def open_login_page(self):
149152
"""Open the browser for the user to authenticate."""
150153
# Construct the authorization URL pointing to /login
151154
auth_url = f"{auth_server}/login"
152-
client_id = os.getenv('SLP_CLIENT_ID', 'smartloop-cli')
153155
full_auth_url = f"{auth_url}?response_type=code&redirect_uri={self.redirect_uri}&state={self.state}&client_id={client_id}"
154156
# Open the authorization URL in the user's default browser
155157
webbrowser.open(full_auth_url)
@@ -165,7 +167,6 @@ def perform_browser_login(callback_port=5000, timeout=120):
165167
login_handler.start_server()
166168
login_handler.open_login_page()
167169

168-
client_id = os.getenv('SLP_CLIENT_ID', 'smartloop-cli')
169170
print("A browser window has been opened for you to complete the login process.")
170171
print("If it doesn't open automatically, please go to the following URL:")
171172
print(f"{auth_server}/login?response_type=code&redirect_uri=http://localhost:{login_handler.port}/callback&state={login_handler.state}&client_id={client_id}")

0 commit comments

Comments
 (0)