sendvrel-login 1.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.4
2
+ Name: sendvrel-login
3
+ Version: 1.1.3
4
+ Summary: Official Python SDK for Sendvrel OAuth Login
5
+ Author: Sendvrel
6
+ Requires-Python: >=3.6
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: requests>=2.25.1
9
+ Dynamic: author
10
+ Dynamic: description
11
+ Dynamic: description-content-type
12
+ Dynamic: requires-dist
13
+ Dynamic: requires-python
14
+ Dynamic: summary
15
+
16
+ # sendvrel-login-python
17
+
18
+ > **Critical Update Added: Important PKCE Security Fix**. Please upgrade to the latest version immediately to maintain login functionality with Sendvrel.
19
+
20
+ Official Python SDK for Sendvrel Authentication.
21
+
22
+ 🚀 Quick Start (Zero-Config)
23
+ -----------------------------
24
+ Easily integrate Sendvrel OAuth 2.0 into your Python backends (Django, Flask, FastAPI).
25
+ This package acts as a full **Confidential Client**, capable of handling authorization URLs, secure token exchanges, and token verification.
26
+
27
+ ### Installation
28
+ ```bash
29
+ pip install sendvrel-login
30
+ ```
31
+
32
+ 🛠️ Usage
33
+ ---------
34
+ ### 1. Generating the Authorization URL
35
+ Redirect your users to this URL so they can log in via Sendvrel.
36
+
37
+ ```python
38
+ from sendvrel_login import TSPClient
39
+
40
+ client = TSPClient(
41
+ client_id='YOUR_CLIENT_ID',
42
+ client_secret='YOUR_CLIENT_SECRET',
43
+ redirect_uri='http://localhost:8000/callback'
44
+ )
45
+
46
+ auth_url = client.get_authorization_url()
47
+ # Redirect your user to `auth_url`
48
+ ```
49
+
50
+ ### 2. Exchanging the Code for a Token
51
+ When the user returns to your `redirect_uri`, they will have a `code` in the URL parameters.
52
+
53
+ ```python
54
+ # Assuming you extracted the `code` from the URL query string
55
+ token_data = client.exchange_token(code)
56
+
57
+ if 'error' in token_data:
58
+ print("Failed to login:", token_data['error'])
59
+ else:
60
+ access_token = token_data['access_token']
61
+ print("Successfully retrieved access token!", access_token)
62
+ ```
63
+
64
+ ### 3. Verifying a Token / Getting the User Profile
65
+ Once you have an access token (or if you are just verifying a token sent by a React frontend), use `verify_token`.
66
+
67
+ ```python
68
+ from sendvrel_login import TSPAuthException
69
+
70
+ try:
71
+ data = client.verify_token(access_token)
72
+ user_profile = data['user']
73
+ print(f"Logged in as: {user_profile['email']}")
74
+ except TSPAuthException as error:
75
+ print(f"Authentication failed: {str(error)}")
76
+ ```
77
+
@@ -0,0 +1,62 @@
1
+ # sendvrel-login-python
2
+
3
+ > **Critical Update Added: Important PKCE Security Fix**. Please upgrade to the latest version immediately to maintain login functionality with Sendvrel.
4
+
5
+ Official Python SDK for Sendvrel Authentication.
6
+
7
+ 🚀 Quick Start (Zero-Config)
8
+ -----------------------------
9
+ Easily integrate Sendvrel OAuth 2.0 into your Python backends (Django, Flask, FastAPI).
10
+ This package acts as a full **Confidential Client**, capable of handling authorization URLs, secure token exchanges, and token verification.
11
+
12
+ ### Installation
13
+ ```bash
14
+ pip install sendvrel-login
15
+ ```
16
+
17
+ 🛠️ Usage
18
+ ---------
19
+ ### 1. Generating the Authorization URL
20
+ Redirect your users to this URL so they can log in via Sendvrel.
21
+
22
+ ```python
23
+ from sendvrel_login import TSPClient
24
+
25
+ client = TSPClient(
26
+ client_id='YOUR_CLIENT_ID',
27
+ client_secret='YOUR_CLIENT_SECRET',
28
+ redirect_uri='http://localhost:8000/callback'
29
+ )
30
+
31
+ auth_url = client.get_authorization_url()
32
+ # Redirect your user to `auth_url`
33
+ ```
34
+
35
+ ### 2. Exchanging the Code for a Token
36
+ When the user returns to your `redirect_uri`, they will have a `code` in the URL parameters.
37
+
38
+ ```python
39
+ # Assuming you extracted the `code` from the URL query string
40
+ token_data = client.exchange_token(code)
41
+
42
+ if 'error' in token_data:
43
+ print("Failed to login:", token_data['error'])
44
+ else:
45
+ access_token = token_data['access_token']
46
+ print("Successfully retrieved access token!", access_token)
47
+ ```
48
+
49
+ ### 3. Verifying a Token / Getting the User Profile
50
+ Once you have an access token (or if you are just verifying a token sent by a React frontend), use `verify_token`.
51
+
52
+ ```python
53
+ from sendvrel_login import TSPAuthException
54
+
55
+ try:
56
+ data = client.verify_token(access_token)
57
+ user_profile = data['user']
58
+ print(f"Logged in as: {user_profile['email']}")
59
+ except TSPAuthException as error:
60
+ print(f"Authentication failed: {str(error)}")
61
+ ```
62
+
@@ -0,0 +1,3 @@
1
+ from .client import TSPClient, TSPAuthException
2
+
3
+ __all__ = ['TSPClient', 'TSPAuthException']
@@ -0,0 +1,101 @@
1
+ import requests
2
+ from urllib.parse import urlencode
3
+ import os
4
+ import base64
5
+ import hashlib
6
+
7
+ class TSPAuthException(Exception):
8
+ pass
9
+
10
+ class TSPClient:
11
+ def __init__(self, client_id=None, client_secret=None, redirect_uri=None, api_url='https://api.sendvrel.kystron.com/api/v1', auth_url='https://accounts.kystron.com/oauth/authorize'):
12
+ self.api_url = api_url.rstrip('/')
13
+ self.auth_url = auth_url.rstrip('/')
14
+ self.client_id = client_id
15
+ self.client_secret = client_secret
16
+ self.redirect_uri = redirect_uri
17
+
18
+ def get_authorization_url(self, state='tsp_auth', scope='read', pkce_challenge=None):
19
+ """
20
+ Generates the OAuth 2.0 Authorization URL to redirect the user to.
21
+ """
22
+ if not self.client_id or not self.redirect_uri:
23
+ raise TSPAuthException('TSPClient requires client_id and redirect_uri to generate an authorization URL.')
24
+
25
+ params = {
26
+ 'client_id': self.client_id,
27
+ 'redirect_uri': self.redirect_uri,
28
+ 'response_type': 'code',
29
+ 'scope': scope,
30
+ 'state': state
31
+ }
32
+
33
+ if pkce_challenge:
34
+ params['code_challenge'] = pkce_challenge
35
+ params['code_challenge_method'] = 'S256'
36
+
37
+ return f"{self.auth_url}?{urlencode(params)}"
38
+
39
+ def exchange_token(self, code, code_verifier=None):
40
+ """
41
+ Securely exchanges an authorization code for an access token.
42
+ """
43
+ if not self.client_id or not self.client_secret or not self.redirect_uri:
44
+ raise TSPAuthException('TSPClient requires client_id, client_secret, and redirect_uri to exchange tokens.')
45
+
46
+ payload = {
47
+ 'grant_type': 'authorization_code',
48
+ 'client_id': self.client_id,
49
+ 'client_secret': self.client_secret,
50
+ 'code': code,
51
+ 'redirect_uri': self.redirect_uri
52
+ }
53
+
54
+ if code_verifier:
55
+ payload['code_verifier'] = code_verifier
56
+
57
+ try:
58
+ response = requests.post(f'{self.api_url}/oauth/token', json=payload)
59
+ data = response.json()
60
+
61
+ if not response.ok:
62
+ return {'error': data.get('error', 'Failed to exchange token')}
63
+
64
+ return {'access_token': data.get('access_token')}
65
+ except requests.RequestException as e:
66
+ return {'error': f'Network error exchanging token: {str(e)}'}
67
+
68
+ def verify_token(self, access_token):
69
+ """
70
+ Verifies an access token with the Sendvrel backend.
71
+
72
+ :param access_token: The OAuth 2.0 Access Token
73
+ :return: A dictionary containing the user's profile
74
+ :raises TSPAuthException: If the token is invalid or expired
75
+ """
76
+ headers = {
77
+ 'Authorization': f'Bearer {access_token}',
78
+ 'Content-Type': 'application/json'
79
+ }
80
+
81
+ try:
82
+ response = requests.get(f'{self.api_url}/oauth/userinfo', headers=headers)
83
+ data = response.json()
84
+
85
+ if not response.ok:
86
+ raise TSPAuthException(data.get('error', 'Failed to verify token'))
87
+
88
+ return {'user': data}
89
+ except requests.RequestException as e:
90
+ raise TSPAuthException(f'Network error verifying token: {str(e)}')
91
+
92
+ def generate_pkce():
93
+ """
94
+ Utility to generate PKCE Verifier and Challenge pairs
95
+ """
96
+ verifier = base64.urlsafe_b64encode(os.urandom(32)).decode('utf-8').rstrip('=')
97
+ challenge = base64.urlsafe_b64encode(
98
+ hashlib.sha256(verifier.encode('utf-8')).digest()
99
+ ).decode('utf-8').rstrip('=')
100
+ return verifier, challenge
101
+
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.4
2
+ Name: sendvrel-login
3
+ Version: 1.1.3
4
+ Summary: Official Python SDK for Sendvrel OAuth Login
5
+ Author: Sendvrel
6
+ Requires-Python: >=3.6
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: requests>=2.25.1
9
+ Dynamic: author
10
+ Dynamic: description
11
+ Dynamic: description-content-type
12
+ Dynamic: requires-dist
13
+ Dynamic: requires-python
14
+ Dynamic: summary
15
+
16
+ # sendvrel-login-python
17
+
18
+ > **Critical Update Added: Important PKCE Security Fix**. Please upgrade to the latest version immediately to maintain login functionality with Sendvrel.
19
+
20
+ Official Python SDK for Sendvrel Authentication.
21
+
22
+ 🚀 Quick Start (Zero-Config)
23
+ -----------------------------
24
+ Easily integrate Sendvrel OAuth 2.0 into your Python backends (Django, Flask, FastAPI).
25
+ This package acts as a full **Confidential Client**, capable of handling authorization URLs, secure token exchanges, and token verification.
26
+
27
+ ### Installation
28
+ ```bash
29
+ pip install sendvrel-login
30
+ ```
31
+
32
+ 🛠️ Usage
33
+ ---------
34
+ ### 1. Generating the Authorization URL
35
+ Redirect your users to this URL so they can log in via Sendvrel.
36
+
37
+ ```python
38
+ from sendvrel_login import TSPClient
39
+
40
+ client = TSPClient(
41
+ client_id='YOUR_CLIENT_ID',
42
+ client_secret='YOUR_CLIENT_SECRET',
43
+ redirect_uri='http://localhost:8000/callback'
44
+ )
45
+
46
+ auth_url = client.get_authorization_url()
47
+ # Redirect your user to `auth_url`
48
+ ```
49
+
50
+ ### 2. Exchanging the Code for a Token
51
+ When the user returns to your `redirect_uri`, they will have a `code` in the URL parameters.
52
+
53
+ ```python
54
+ # Assuming you extracted the `code` from the URL query string
55
+ token_data = client.exchange_token(code)
56
+
57
+ if 'error' in token_data:
58
+ print("Failed to login:", token_data['error'])
59
+ else:
60
+ access_token = token_data['access_token']
61
+ print("Successfully retrieved access token!", access_token)
62
+ ```
63
+
64
+ ### 3. Verifying a Token / Getting the User Profile
65
+ Once you have an access token (or if you are just verifying a token sent by a React frontend), use `verify_token`.
66
+
67
+ ```python
68
+ from sendvrel_login import TSPAuthException
69
+
70
+ try:
71
+ data = client.verify_token(access_token)
72
+ user_profile = data['user']
73
+ print(f"Logged in as: {user_profile['email']}")
74
+ except TSPAuthException as error:
75
+ print(f"Authentication failed: {str(error)}")
76
+ ```
77
+
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ sendvrel_login/__init__.py
4
+ sendvrel_login/client.py
5
+ sendvrel_login.egg-info/PKG-INFO
6
+ sendvrel_login.egg-info/SOURCES.txt
7
+ sendvrel_login.egg-info/dependency_links.txt
8
+ sendvrel_login.egg-info/requires.txt
9
+ sendvrel_login.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ requests>=2.25.1
@@ -0,0 +1 @@
1
+ sendvrel_login
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ from setuptools import setup, find_packages
2
+ from pathlib import Path
3
+
4
+ this_directory = Path(__file__).parent
5
+ long_description = (this_directory / "README.md").read_text(encoding='utf-8')
6
+
7
+ setup(
8
+ name='sendvrel-login',
9
+ version='1.1.3',
10
+ description='Official Python SDK for Sendvrel OAuth Login',
11
+ long_description=long_description,
12
+ long_description_content_type='text/markdown',
13
+ author='Sendvrel',
14
+ packages=find_packages(),
15
+ install_requires=[
16
+ 'requests>=2.25.1'
17
+ ],
18
+ python_requires='>=3.6',
19
+ )