ipulse-shared-core-ftredge 22.1.1__py3-none-any.whl → 23.1.1__py3-none-any.whl
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.
Potentially problematic release.
This version of ipulse-shared-core-ftredge might be problematic. Click here for more details.
- ipulse_shared_core_ftredge/dependencies/auth_firebase_token_validation.py +60 -23
- ipulse_shared_core_ftredge/dependencies/authz_for_apis.py +128 -157
- ipulse_shared_core_ftredge/exceptions/base_exceptions.py +12 -4
- ipulse_shared_core_ftredge/models/catalog/subscriptionplan.py +4 -3
- ipulse_shared_core_ftredge/models/catalog/usertype.py +8 -1
- ipulse_shared_core_ftredge/models/user/user_subscription.py +142 -30
- ipulse_shared_core_ftredge/models/user/userstatus.py +63 -14
- ipulse_shared_core_ftredge/services/base/base_firestore_service.py +5 -3
- ipulse_shared_core_ftredge/services/catalog/catalog_subscriptionplan_service.py +27 -23
- ipulse_shared_core_ftredge/services/catalog/catalog_usertype_service.py +94 -25
- ipulse_shared_core_ftredge/services/user/user_core_service.py +141 -23
- ipulse_shared_core_ftredge/services/user/user_multistep_operations.py +144 -74
- ipulse_shared_core_ftredge/services/user/user_subscription_operations.py +24 -20
- ipulse_shared_core_ftredge/services/user/userstatus_operations.py +268 -4
- {ipulse_shared_core_ftredge-22.1.1.dist-info → ipulse_shared_core_ftredge-23.1.1.dist-info}/METADATA +1 -1
- {ipulse_shared_core_ftredge-22.1.1.dist-info → ipulse_shared_core_ftredge-23.1.1.dist-info}/RECORD +19 -20
- ipulse_shared_core_ftredge/services/user/firebase_auth_admin_helpers.py +0 -160
- {ipulse_shared_core_ftredge-22.1.1.dist-info → ipulse_shared_core_ftredge-23.1.1.dist-info}/WHEEL +0 -0
- {ipulse_shared_core_ftredge-22.1.1.dist-info → ipulse_shared_core_ftredge-23.1.1.dist-info}/licenses/LICENCE +0 -0
- {ipulse_shared_core_ftredge-22.1.1.dist-info → ipulse_shared_core_ftredge-23.1.1.dist-info}/top_level.txt +0 -0
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Firebase Admin Helper Functions
|
|
3
|
-
|
|
4
|
-
This module provides utility functions for managing Firebase Auth users and permissions.
|
|
5
|
-
These functions are designed for admin operations and testing purposes.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import os
|
|
9
|
-
import time
|
|
10
|
-
import logging
|
|
11
|
-
from typing import Dict, Any, List, Optional, Tuple
|
|
12
|
-
import firebase_admin
|
|
13
|
-
from firebase_admin import auth
|
|
14
|
-
from ipulse_shared_base_ftredge import log_info, log_warning, log_error, log_debug, LogLevel
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def get_user_auth_token(
|
|
18
|
-
email: str,
|
|
19
|
-
password: str,
|
|
20
|
-
api_key: str,
|
|
21
|
-
logger: Optional[logging.Logger] = None,
|
|
22
|
-
print_out: bool = False,
|
|
23
|
-
debug: bool = False
|
|
24
|
-
) -> Optional[str]:
|
|
25
|
-
"""
|
|
26
|
-
Get a user authentication token using the Firebase REST API.
|
|
27
|
-
|
|
28
|
-
Args:
|
|
29
|
-
email: User email
|
|
30
|
-
password: User password
|
|
31
|
-
api_key: Firebase API key
|
|
32
|
-
logger: Optional logger instance
|
|
33
|
-
print_out: Whether to print output
|
|
34
|
-
debug: Whether to print detailed debug info
|
|
35
|
-
|
|
36
|
-
Returns:
|
|
37
|
-
ID token or None if failed
|
|
38
|
-
"""
|
|
39
|
-
import requests # Import here to keep it optional
|
|
40
|
-
|
|
41
|
-
url = f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key={api_key}"
|
|
42
|
-
payload = {
|
|
43
|
-
"email": email,
|
|
44
|
-
"password": password,
|
|
45
|
-
"returnSecureToken": True
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
try:
|
|
49
|
-
if debug:
|
|
50
|
-
log_info(f"Sending authentication request to: {url}", logger=logger, print_out=print_out)
|
|
51
|
-
log_info(f"Request payload: {payload}", logger=logger, print_out=print_out)
|
|
52
|
-
|
|
53
|
-
response = requests.post(url, json=payload)
|
|
54
|
-
|
|
55
|
-
# Add detailed error logging
|
|
56
|
-
if not response.ok:
|
|
57
|
-
error_details = response.text
|
|
58
|
-
try:
|
|
59
|
-
error_json = response.json()
|
|
60
|
-
if "error" in error_json:
|
|
61
|
-
error_details = f"{error_json['error'].get('message', 'Unknown error')}"
|
|
62
|
-
except Exception:
|
|
63
|
-
pass
|
|
64
|
-
|
|
65
|
-
log_error(f"Auth error ({response.status_code}): {error_details}", logger=logger, print_out=print_out)
|
|
66
|
-
|
|
67
|
-
# Check for specific error conditions
|
|
68
|
-
if "EMAIL_NOT_FOUND" in error_details or "INVALID_PASSWORD" in error_details:
|
|
69
|
-
log_error(f"Authentication failed - invalid credentials for {email}", logger=logger, print_out=print_out)
|
|
70
|
-
elif "USER_DISABLED" in error_details:
|
|
71
|
-
log_error(f"User account is disabled: {email}", logger=logger, print_out=print_out)
|
|
72
|
-
elif "INVALID_EMAIL" in error_details:
|
|
73
|
-
log_error(f"Invalid email format: {email}", logger=logger, print_out=print_out)
|
|
74
|
-
|
|
75
|
-
return None
|
|
76
|
-
|
|
77
|
-
token = response.json().get("idToken")
|
|
78
|
-
log_info(f"Successfully obtained auth token for {email}", logger=logger, print_out=print_out)
|
|
79
|
-
return token
|
|
80
|
-
except Exception as e:
|
|
81
|
-
log_error(f"Error getting auth token: {e}", logger=logger, print_out=print_out)
|
|
82
|
-
return None
|
|
83
|
-
|
|
84
|
-
def list_users(max_results: int = 1000, logger: Optional[logging.Logger] = None, print_out: bool = False) -> List[Dict[str, Any]]:
|
|
85
|
-
"""
|
|
86
|
-
List users from Firebase Auth.
|
|
87
|
-
|
|
88
|
-
Args:
|
|
89
|
-
max_results: Maximum number of users to return
|
|
90
|
-
logger: Optional logger instance
|
|
91
|
-
print_out: Whether to print output
|
|
92
|
-
|
|
93
|
-
Returns:
|
|
94
|
-
List of user dicts
|
|
95
|
-
"""
|
|
96
|
-
try:
|
|
97
|
-
users = []
|
|
98
|
-
page = auth.list_users()
|
|
99
|
-
for user in page.users:
|
|
100
|
-
users.append(user._data)
|
|
101
|
-
if len(users) >= max_results:
|
|
102
|
-
break
|
|
103
|
-
|
|
104
|
-
log_info(f"Listed {len(users)} users from Firebase Auth", logger=logger, print_out=print_out)
|
|
105
|
-
return users
|
|
106
|
-
except Exception as e:
|
|
107
|
-
log_error(f"Error listing users: {e}", logger=logger, print_out=print_out)
|
|
108
|
-
return []
|
|
109
|
-
|
|
110
|
-
def create_custom_token(
|
|
111
|
-
user_uid: str,
|
|
112
|
-
additional_claims: Dict[str, Any] = None,
|
|
113
|
-
logger: Optional[logging.Logger] = None,
|
|
114
|
-
print_out: bool = False
|
|
115
|
-
) -> str:
|
|
116
|
-
"""
|
|
117
|
-
Create a custom token for a user.
|
|
118
|
-
|
|
119
|
-
Args:
|
|
120
|
-
user_uid: User's UID
|
|
121
|
-
additional_claims: Additional claims to include in the token
|
|
122
|
-
logger: Optional logger instance
|
|
123
|
-
print_out: Whether to print output
|
|
124
|
-
|
|
125
|
-
Returns:
|
|
126
|
-
Custom token
|
|
127
|
-
"""
|
|
128
|
-
try:
|
|
129
|
-
token = auth.create_custom_token(user_uid, additional_claims)
|
|
130
|
-
log_debug(f"Created custom token for user {user_uid}", logger=logger, print_out=print_out)
|
|
131
|
-
return token
|
|
132
|
-
except Exception as e:
|
|
133
|
-
log_error(f"Error creating custom token: {e}", logger=logger, print_out=print_out)
|
|
134
|
-
raise
|
|
135
|
-
|
|
136
|
-
def verify_id_token(
|
|
137
|
-
token: str,
|
|
138
|
-
check_revoked: bool = False,
|
|
139
|
-
logger: Optional[logging.Logger] = None,
|
|
140
|
-
print_out: bool = False
|
|
141
|
-
) -> Dict[str, Any]:
|
|
142
|
-
"""
|
|
143
|
-
Verify an ID token.
|
|
144
|
-
|
|
145
|
-
Args:
|
|
146
|
-
token: ID token to verify
|
|
147
|
-
check_revoked: Whether to check if the token has been revoked
|
|
148
|
-
logger: Optional logger instance
|
|
149
|
-
print_out: Whether to print output
|
|
150
|
-
|
|
151
|
-
Returns:
|
|
152
|
-
Token claims
|
|
153
|
-
"""
|
|
154
|
-
try:
|
|
155
|
-
claims = auth.verify_id_token(token, check_revoked=check_revoked)
|
|
156
|
-
log_debug(f"Verified ID token for user {claims.get('uid')}", logger=logger, print_out=print_out)
|
|
157
|
-
return claims
|
|
158
|
-
except Exception as e:
|
|
159
|
-
log_error(f"Error verifying ID token: {e}", logger=logger, print_out=print_out)
|
|
160
|
-
raise
|
{ipulse_shared_core_ftredge-22.1.1.dist-info → ipulse_shared_core_ftredge-23.1.1.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|