Metadata-Version: 2.4
Name: tspscale-login
Version: 1.1.0
Summary: Official Python SDK for TSP Scale OAuth Login
Author: TSP Scale
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.25.1
Dynamic: author
Dynamic: description
Dynamic: description-content-type
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# tspscale-login

Official Python SDK for TSP Scale Authentication.

🚀 Quick Start (Zero-Config)
-----------------------------
Easily integrate TSP Scale OAuth 2.0 into your Python backends (Django, Flask, FastAPI). 
This package acts as a full **Confidential Client**, capable of handling authorization URLs, secure token exchanges, and token verification.

### Installation
```bash
pip install tspscale-login
```

🛠️ Usage
---------
### 1. Generating the Authorization URL
Redirect your users to this URL so they can log in via TSP Scale.

```python
from tspscale_login import TSPClient

client = TSPClient(
    client_id='YOUR_CLIENT_ID',
    client_secret='YOUR_CLIENT_SECRET',
    redirect_uri='http://localhost:8000/callback'
)

auth_url = client.get_authorization_url()
# Redirect your user to `auth_url`
```

### 2. Exchanging the Code for a Token
When the user returns to your `redirect_uri`, they will have a `code` in the URL parameters.

```python
# Assuming you extracted the `code` from the URL query string
token_data = client.exchange_token(code)

if 'error' in token_data:
    print("Failed to login:", token_data['error'])
else:
    access_token = token_data['access_token']
    print("Successfully retrieved access token!", access_token)
```

### 3. Verifying a Token / Getting the User Profile
Once you have an access token (or if you are just verifying a token sent by a React frontend), use `verify_token`.

```python
from tspscale_login import TSPAuthException

try:
    data = client.verify_token(access_token)
    user_profile = data['user']
    print(f"Logged in as: {user_profile['email']}")
except TSPAuthException as error:
    print(f"Authentication failed: {str(error)}")
```
