propelauth-fastapi 4.4.0__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.
|
@@ -0,0 +1,1363 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from datetime import date
|
|
3
|
+
from typing import Any, Dict, List, Optional
|
|
4
|
+
from fastapi import Depends, HTTPException, Header
|
|
5
|
+
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
|
6
|
+
|
|
7
|
+
from propelauth_py import (
|
|
8
|
+
SetOidcIdpMetadataRequest,
|
|
9
|
+
SocialLoginTokenProvider,
|
|
10
|
+
TokenVerificationMetadata,
|
|
11
|
+
configure_logging,
|
|
12
|
+
init_base_auth,
|
|
13
|
+
init_base_async_auth,
|
|
14
|
+
SamlIdpMetadata,
|
|
15
|
+
StepUpMfaGrantType,
|
|
16
|
+
StepUpMfaVerifyTotpResponse,
|
|
17
|
+
)
|
|
18
|
+
from propelauth_py.errors import ForbiddenException, UnauthorizedException
|
|
19
|
+
from propelauth_py.user import User
|
|
20
|
+
from propelauth_py.types.user_insights import (
|
|
21
|
+
ChartMetric,
|
|
22
|
+
ChartMetricCadence,
|
|
23
|
+
ChartData,
|
|
24
|
+
TopInviterReportInterval,
|
|
25
|
+
ChampionReportInterval,
|
|
26
|
+
ChurnReportInterval,
|
|
27
|
+
ReengagementReportInterval,
|
|
28
|
+
GrowthReportInterval,
|
|
29
|
+
AttritionReportInterval,
|
|
30
|
+
OrgReport,
|
|
31
|
+
OrgReportType,
|
|
32
|
+
UserReport,
|
|
33
|
+
UserReportType,
|
|
34
|
+
)
|
|
35
|
+
from propelauth_py.api import (
|
|
36
|
+
OrgQueryOrderBy,
|
|
37
|
+
UserQueryOrderBy,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
_security = HTTPBearer(auto_error=False)
|
|
41
|
+
|
|
42
|
+
def _require_org_member_wrapper(auth, debug_mode: bool):
|
|
43
|
+
def require_org_member(user: User, required_org_id: str):
|
|
44
|
+
try:
|
|
45
|
+
return auth.validate_org_access_and_get_org(user, required_org_id)
|
|
46
|
+
except ForbiddenException as e:
|
|
47
|
+
_handle_forbidden_exception(e, debug_mode)
|
|
48
|
+
|
|
49
|
+
return require_org_member
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _require_org_member_with_minimum_role_wrapper(auth, debug_mode: bool):
|
|
53
|
+
def require_org_member_with_minimum_role(
|
|
54
|
+
user: User, required_org_id: str, minimum_required_role: str
|
|
55
|
+
):
|
|
56
|
+
try:
|
|
57
|
+
return auth.validate_minimum_org_role_and_get_org(
|
|
58
|
+
user, required_org_id, minimum_required_role
|
|
59
|
+
)
|
|
60
|
+
except ForbiddenException as e:
|
|
61
|
+
_handle_forbidden_exception(e, debug_mode)
|
|
62
|
+
|
|
63
|
+
return require_org_member_with_minimum_role
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _require_org_member_with_exact_role_wrapper(auth, debug_mode: bool):
|
|
67
|
+
def require_org_member_with_exact_role(user: User, required_org_id: str, role: str):
|
|
68
|
+
try:
|
|
69
|
+
return auth.validate_exact_org_role_and_get_org(user, required_org_id, role)
|
|
70
|
+
except ForbiddenException as e:
|
|
71
|
+
_handle_forbidden_exception(e, debug_mode)
|
|
72
|
+
|
|
73
|
+
return require_org_member_with_exact_role
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _require_org_member_with_permission_wrapper(auth, debug_mode: bool):
|
|
77
|
+
def require_org_member_with_permission(
|
|
78
|
+
user: User, required_org_id: str, permission: str
|
|
79
|
+
):
|
|
80
|
+
try:
|
|
81
|
+
return auth.validate_permission_and_get_org(
|
|
82
|
+
user, required_org_id, permission
|
|
83
|
+
)
|
|
84
|
+
except ForbiddenException as e:
|
|
85
|
+
_handle_forbidden_exception(e, debug_mode)
|
|
86
|
+
|
|
87
|
+
return require_org_member_with_permission
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _require_org_member_with_all_permissions_wrapper(auth, debug_mode: bool):
|
|
91
|
+
def require_org_member_with_all_permissions(
|
|
92
|
+
user: User, required_org_id: str, permissions: List[str]
|
|
93
|
+
):
|
|
94
|
+
try:
|
|
95
|
+
return auth.validate_all_permissions_and_get_org(
|
|
96
|
+
user, required_org_id, permissions
|
|
97
|
+
)
|
|
98
|
+
except ForbiddenException as e:
|
|
99
|
+
_handle_forbidden_exception(e, debug_mode)
|
|
100
|
+
|
|
101
|
+
return require_org_member_with_all_permissions
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _handle_forbidden_exception(e: ForbiddenException, debug_mode: bool):
|
|
105
|
+
if debug_mode:
|
|
106
|
+
raise HTTPException(status_code=403, detail=e.message)
|
|
107
|
+
else:
|
|
108
|
+
raise HTTPException(status_code=403)
|
|
109
|
+
|
|
110
|
+
class FastAPIAuth:
|
|
111
|
+
def __init__(self, auth_url: str, integration_api_key: str, token_verification_metadata: Optional[TokenVerificationMetadata], debug_mode: bool):
|
|
112
|
+
self.auth_url = auth_url
|
|
113
|
+
self.integration_api_key = integration_api_key
|
|
114
|
+
self.token_verification_metadata = token_verification_metadata
|
|
115
|
+
self.debug_mode = debug_mode
|
|
116
|
+
self.auth = init_base_auth(auth_url, integration_api_key, token_verification_metadata)
|
|
117
|
+
|
|
118
|
+
def require_user(self, credentials: HTTPAuthorizationCredentials = Depends(_security)):
|
|
119
|
+
try:
|
|
120
|
+
# Pass it in to the underlying function to get consistent error messages
|
|
121
|
+
if credentials is None:
|
|
122
|
+
authorization_header = ""
|
|
123
|
+
else:
|
|
124
|
+
authorization_header = (
|
|
125
|
+
credentials.scheme + " " + credentials.credentials
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
user = self.auth.validate_access_token_and_get_user(authorization_header)
|
|
129
|
+
return user
|
|
130
|
+
except UnauthorizedException as e:
|
|
131
|
+
if self.debug_mode:
|
|
132
|
+
raise HTTPException(status_code=401, detail=e.message)
|
|
133
|
+
else:
|
|
134
|
+
raise HTTPException(status_code=401)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def optional_user(self, credentials: HTTPAuthorizationCredentials = Depends(_security)):
|
|
138
|
+
if credentials is None:
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
try:
|
|
142
|
+
authorization_header = credentials.scheme + " " + credentials.credentials
|
|
143
|
+
user = self.auth.validate_access_token_and_get_user(authorization_header)
|
|
144
|
+
return user
|
|
145
|
+
except UnauthorizedException:
|
|
146
|
+
return None
|
|
147
|
+
|
|
148
|
+
def require_org_member(self, user: User, required_org_id: str):
|
|
149
|
+
try:
|
|
150
|
+
return self.auth.validate_org_access_and_get_org(user, required_org_id)
|
|
151
|
+
except ForbiddenException as e:
|
|
152
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
153
|
+
|
|
154
|
+
def require_org_member_with_minimum_role(self, user: User, required_org_id: str, minimum_required_role: str):
|
|
155
|
+
try:
|
|
156
|
+
return self.auth.validate_minimum_org_role_and_get_org(
|
|
157
|
+
user, required_org_id, minimum_required_role
|
|
158
|
+
)
|
|
159
|
+
except ForbiddenException as e:
|
|
160
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
161
|
+
|
|
162
|
+
def require_org_member_with_exact_role(self, user: User, required_org_id: str, role: str):
|
|
163
|
+
try:
|
|
164
|
+
return self.auth.validate_exact_org_role_and_get_org(user, required_org_id, role)
|
|
165
|
+
except ForbiddenException as e:
|
|
166
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
167
|
+
|
|
168
|
+
def require_org_member_with_permission(self, user: User, required_org_id: str, permission: str):
|
|
169
|
+
try:
|
|
170
|
+
return self.auth.validate_permission_and_get_org(
|
|
171
|
+
user, required_org_id, permission
|
|
172
|
+
)
|
|
173
|
+
except ForbiddenException as e:
|
|
174
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
175
|
+
|
|
176
|
+
def require_org_member_with_all_permissions(self, user: User, required_org_id: str, permissions: List[str]):
|
|
177
|
+
try:
|
|
178
|
+
return self.auth.validate_all_permissions_and_get_org(
|
|
179
|
+
user, required_org_id, permissions
|
|
180
|
+
)
|
|
181
|
+
except ForbiddenException as e:
|
|
182
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
183
|
+
|
|
184
|
+
def validate_access_token_and_get_user(self, authorization_header: str) -> User:
|
|
185
|
+
return self.auth.validate_access_token_and_get_user(authorization_header=authorization_header)
|
|
186
|
+
|
|
187
|
+
def fetch_user_metadata_by_user_id(self, user_id: str, include_orgs: bool = False):
|
|
188
|
+
return self.auth.fetch_user_metadata_by_user_id(user_id, include_orgs)
|
|
189
|
+
|
|
190
|
+
def fetch_user_metadata_by_email(self, email: str, include_orgs: bool = False):
|
|
191
|
+
return self.auth.fetch_user_metadata_by_email(email, include_orgs)
|
|
192
|
+
|
|
193
|
+
def fetch_user_metadata_by_username(self, username: str, include_orgs: bool = False):
|
|
194
|
+
return self.auth.fetch_user_metadata_by_username(username, include_orgs)
|
|
195
|
+
|
|
196
|
+
def fetch_user_signup_query_params_by_user_id(self, user_id: str):
|
|
197
|
+
return self.auth.fetch_user_signup_query_params_by_user_id(user_id)
|
|
198
|
+
|
|
199
|
+
def fetch_batch_user_metadata_by_user_ids(self, user_ids: List[str], include_orgs: bool = False):
|
|
200
|
+
return self.auth.fetch_batch_user_metadata_by_user_ids(user_ids, include_orgs)
|
|
201
|
+
|
|
202
|
+
def fetch_batch_user_metadata_by_emails(self, emails: List[str], include_orgs: bool = False):
|
|
203
|
+
return self.auth.fetch_batch_user_metadata_by_emails(emails, include_orgs)
|
|
204
|
+
|
|
205
|
+
def fetch_batch_user_metadata_by_usernames(self, usernames: List[str], include_orgs: bool = False):
|
|
206
|
+
return self.auth.fetch_batch_user_metadata_by_usernames(usernames, include_orgs)
|
|
207
|
+
|
|
208
|
+
def fetch_org(self, org_id: str):
|
|
209
|
+
return self.auth.fetch_org(org_id)
|
|
210
|
+
|
|
211
|
+
def fetch_org_by_query(
|
|
212
|
+
self, page_size: int = 10, page_number: int = 0, order_by: OrgQueryOrderBy = OrgQueryOrderBy.CREATED_AT_ASC,
|
|
213
|
+
name: Optional[str] = None, legacy_org_id: Optional[str] = None, domain: Optional[str] = None
|
|
214
|
+
):
|
|
215
|
+
return self.auth.fetch_org_by_query(page_size, page_number, order_by, name, legacy_org_id, domain)
|
|
216
|
+
|
|
217
|
+
def fetch_custom_role_mappings(self):
|
|
218
|
+
return self.auth.fetch_custom_role_mappings()
|
|
219
|
+
|
|
220
|
+
def fetch_pending_invites(self, page_number: int = 0, page_size: int = 10, org_id: Optional[str] = None):
|
|
221
|
+
return self.auth.fetch_pending_invites(page_number, page_size, org_id)
|
|
222
|
+
|
|
223
|
+
def fetch_users_by_query(
|
|
224
|
+
self, page_size: int = 10, page_number: int = 0, order_by: UserQueryOrderBy = UserQueryOrderBy.CREATED_AT_ASC,
|
|
225
|
+
email_or_username: Optional[str] = None, include_orgs: bool = False, legacy_user_id: Optional[str] = None
|
|
226
|
+
):
|
|
227
|
+
return self.auth.fetch_users_by_query(page_size, page_number, order_by, email_or_username, include_orgs, legacy_user_id)
|
|
228
|
+
|
|
229
|
+
def fetch_users_in_org(
|
|
230
|
+
self, org_id: str, page_size: int = 10, page_number: int = 0, include_orgs: bool = False, role: Optional[str] = None
|
|
231
|
+
):
|
|
232
|
+
return self.auth.fetch_users_in_org(org_id, page_size, page_number, include_orgs, role)
|
|
233
|
+
|
|
234
|
+
def create_user(
|
|
235
|
+
self, email: str, email_confirmed: bool = False, send_email_to_confirm_email_address: bool = True,
|
|
236
|
+
ask_user_to_update_password_on_login: bool = False, password: Optional[str] = None, username: Optional[str] = None,
|
|
237
|
+
first_name: Optional[str] = None, last_name: Optional[str] = None, properties: Optional[Dict[str, Any]] = None, ignore_domain_restrictions: bool = False
|
|
238
|
+
):
|
|
239
|
+
return self.auth.create_user(
|
|
240
|
+
email, email_confirmed, send_email_to_confirm_email_address, ask_user_to_update_password_on_login,
|
|
241
|
+
password, username, first_name, last_name, properties, ignore_domain_restrictions
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
def invite_user_to_org(self, email: str, org_id: str, role: str, additional_roles: List[str] = []):
|
|
245
|
+
return self.auth.invite_user_to_org(email, org_id, role, additional_roles)
|
|
246
|
+
|
|
247
|
+
def resend_email_confirmation(self, user_id: str):
|
|
248
|
+
return self.auth.resend_email_confirmation(user_id)
|
|
249
|
+
|
|
250
|
+
def logout_all_user_sessions(self, user_id: str):
|
|
251
|
+
return self.auth.logout_all_user_sessions(user_id)
|
|
252
|
+
|
|
253
|
+
def update_user_email(self, user_id: str, new_email: str, require_email_confirmation: bool):
|
|
254
|
+
return self.auth.update_user_email(user_id, new_email, require_email_confirmation)
|
|
255
|
+
|
|
256
|
+
def update_user_metadata(
|
|
257
|
+
self,
|
|
258
|
+
user_id: str,
|
|
259
|
+
username: Optional[str] = None,
|
|
260
|
+
first_name: Optional[str] = None,
|
|
261
|
+
last_name: Optional[str] = None,
|
|
262
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
263
|
+
properties: Optional[Dict[str, Any]] = None,
|
|
264
|
+
picture_url: Optional[str] = None,
|
|
265
|
+
update_password_required: Optional[bool] = None,
|
|
266
|
+
legacy_user_id: Optional[str] = None,
|
|
267
|
+
):
|
|
268
|
+
return self.auth.update_user_metadata(
|
|
269
|
+
user_id, username, first_name, last_name, metadata, properties, picture_url, update_password_required, legacy_user_id
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
def clear_user_password(self, user_id: str):
|
|
273
|
+
return self.auth.clear_user_password(user_id)
|
|
274
|
+
|
|
275
|
+
def update_user_password(self, user_id: str, password: str, ask_user_to_update_password_on_login: bool = False):
|
|
276
|
+
return self.auth.update_user_password(user_id, password, ask_user_to_update_password_on_login)
|
|
277
|
+
|
|
278
|
+
def create_magic_link(
|
|
279
|
+
self,
|
|
280
|
+
email: str,
|
|
281
|
+
redirect_to_url: Optional[str] = None,
|
|
282
|
+
expires_in_hours: Optional[int] = None,
|
|
283
|
+
create_new_user_if_one_doesnt_exist: Optional[bool] = None,
|
|
284
|
+
user_signup_query_parameters: Optional[Dict[str, Any]] = None,
|
|
285
|
+
expire_after_first_use: Optional[bool] = None,
|
|
286
|
+
requires_interstitial: Optional[bool] = None,
|
|
287
|
+
):
|
|
288
|
+
return self.auth.create_magic_link(
|
|
289
|
+
email, redirect_to_url, expires_in_hours, create_new_user_if_one_doesnt_exist, user_signup_query_parameters, expire_after_first_use, requires_interstitial
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
def create_access_token(self, user_id: str, duration_in_minutes: int, active_org_id: Optional[str] = None):
|
|
293
|
+
return self.auth.create_access_token(user_id, duration_in_minutes, active_org_id)
|
|
294
|
+
|
|
295
|
+
def migrate_user_from_external_source(
|
|
296
|
+
self,
|
|
297
|
+
email: str,
|
|
298
|
+
email_confirmed: bool,
|
|
299
|
+
existing_user_id: Optional[str] = None,
|
|
300
|
+
existing_password_hash: Optional[str] = None,
|
|
301
|
+
existing_mfa_base32_encoded_secret: Optional[str] = None,
|
|
302
|
+
ask_user_to_update_password_on_login: bool = False,
|
|
303
|
+
enabled: Optional[bool] = None,
|
|
304
|
+
first_name: Optional[str] = None,
|
|
305
|
+
last_name: Optional[str] = None,
|
|
306
|
+
username: Optional[str] = None,
|
|
307
|
+
picture_url: Optional[str] = None,
|
|
308
|
+
properties: Optional[Dict[str, Any]] = None,
|
|
309
|
+
):
|
|
310
|
+
return self.auth.migrate_user_from_external_source(
|
|
311
|
+
email, email_confirmed, existing_user_id, existing_password_hash,
|
|
312
|
+
existing_mfa_base32_encoded_secret, ask_user_to_update_password_on_login,
|
|
313
|
+
enabled, first_name, last_name, username, picture_url, properties
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
def migrate_user_password(
|
|
317
|
+
self,
|
|
318
|
+
user_id: str,
|
|
319
|
+
password_hash: str,
|
|
320
|
+
):
|
|
321
|
+
return self.auth.migrate_user_password(user_id, password_hash)
|
|
322
|
+
|
|
323
|
+
def create_org(
|
|
324
|
+
self,
|
|
325
|
+
name: str,
|
|
326
|
+
enable_auto_joining_by_domain: bool = False,
|
|
327
|
+
members_must_have_matching_domain: bool = False,
|
|
328
|
+
domain: Optional[str] = None,
|
|
329
|
+
max_users: Optional[str] = None,
|
|
330
|
+
custom_role_mapping_name: Optional[str] = None,
|
|
331
|
+
legacy_org_id: Optional[str] = None,
|
|
332
|
+
):
|
|
333
|
+
return self.auth.create_org(
|
|
334
|
+
name, enable_auto_joining_by_domain, members_must_have_matching_domain,
|
|
335
|
+
domain, max_users, custom_role_mapping_name, legacy_org_id
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
def update_org_metadata(
|
|
339
|
+
self,
|
|
340
|
+
org_id: str,
|
|
341
|
+
name: Optional[str] = None,
|
|
342
|
+
can_setup_saml: Optional[bool] = None,
|
|
343
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
344
|
+
max_users: Optional[str] = None,
|
|
345
|
+
can_join_on_email_domain_match: Optional[bool] = None,
|
|
346
|
+
members_must_have_email_domain_match: Optional[bool] = None,
|
|
347
|
+
domain: Optional[str] = None,
|
|
348
|
+
require_2fa_by: Optional[str] = None,
|
|
349
|
+
extra_domains: Optional[List[str]] = None,
|
|
350
|
+
password_rotation_enabled: Optional[bool] = None,
|
|
351
|
+
password_rotation_history_size: Optional[int] = None,
|
|
352
|
+
password_rotation_period: Optional[int] = None,
|
|
353
|
+
):
|
|
354
|
+
return self.auth.update_org_metadata(
|
|
355
|
+
org_id, name, can_setup_saml, metadata, max_users,
|
|
356
|
+
can_join_on_email_domain_match, members_must_have_email_domain_match, domain, require_2fa_by, extra_domains, password_rotation_enabled, password_rotation_history_size, password_rotation_period
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
def subscribe_org_to_role_mapping(self, org_id: str, custom_role_mapping_name: str):
|
|
360
|
+
return self.auth.subscribe_org_to_role_mapping(org_id, custom_role_mapping_name)
|
|
361
|
+
|
|
362
|
+
def delete_org(self, org_id: str):
|
|
363
|
+
return self.auth.delete_org(org_id)
|
|
364
|
+
|
|
365
|
+
def revoke_pending_org_invite(self, org_id: str, invitee_email: str):
|
|
366
|
+
return self.auth.revoke_pending_org_invite(org_id, invitee_email)
|
|
367
|
+
|
|
368
|
+
def add_user_to_org(self, user_id: str, org_id: str, role: str, additional_roles: List[str] = []):
|
|
369
|
+
return self.auth.add_user_to_org(user_id, org_id, role, additional_roles)
|
|
370
|
+
|
|
371
|
+
def remove_user_from_org(self, user_id: str, org_id: str):
|
|
372
|
+
return self.auth.remove_user_from_org(user_id, org_id)
|
|
373
|
+
|
|
374
|
+
def change_user_role_in_org(self, user_id: str, org_id: str, role: str, additional_roles: List[str] = []):
|
|
375
|
+
return self.auth.change_user_role_in_org(user_id, org_id, role, additional_roles)
|
|
376
|
+
|
|
377
|
+
def delete_user(self, user_id: str):
|
|
378
|
+
return self.auth.delete_user(user_id)
|
|
379
|
+
|
|
380
|
+
def disable_user(self, user_id: str):
|
|
381
|
+
return self.auth.disable_user(user_id)
|
|
382
|
+
|
|
383
|
+
def enable_user(self, user_id: str):
|
|
384
|
+
return self.auth.enable_user(user_id)
|
|
385
|
+
|
|
386
|
+
def disable_user_2fa(self, user_id: str):
|
|
387
|
+
return self.auth.disable_user_2fa(user_id)
|
|
388
|
+
|
|
389
|
+
def enable_user_can_create_orgs(self, user_id: str):
|
|
390
|
+
return self.auth.enable_user_can_create_orgs(user_id)
|
|
391
|
+
|
|
392
|
+
def disable_user_can_create_orgs(self, user_id: str):
|
|
393
|
+
return self.auth.disable_user_can_create_orgs(user_id)
|
|
394
|
+
|
|
395
|
+
def allow_org_to_setup_saml_connection(self, org_id: str):
|
|
396
|
+
return self.auth.allow_org_to_setup_saml_connection(org_id)
|
|
397
|
+
|
|
398
|
+
def disallow_org_to_setup_saml_connection(self, org_id: str):
|
|
399
|
+
return self.auth.disallow_org_to_setup_saml_connection(org_id)
|
|
400
|
+
|
|
401
|
+
def fetch_api_key(self, api_key_id: str):
|
|
402
|
+
return self.auth.fetch_api_key(api_key_id)
|
|
403
|
+
|
|
404
|
+
def fetch_current_api_keys(
|
|
405
|
+
self,
|
|
406
|
+
org_id: Optional[str] = None,
|
|
407
|
+
user_id: Optional[str] = None,
|
|
408
|
+
user_email: Optional[str] = None,
|
|
409
|
+
page_size: Optional[int] = None,
|
|
410
|
+
page_number: Optional[int] = None,
|
|
411
|
+
api_key_type: Optional[str] = None,
|
|
412
|
+
):
|
|
413
|
+
return self.auth.fetch_current_api_keys(
|
|
414
|
+
org_id, user_id, user_email, page_size, page_number, api_key_type
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
def fetch_archived_api_keys(
|
|
418
|
+
self,
|
|
419
|
+
org_id: Optional[str] = None,
|
|
420
|
+
user_id: Optional[str] = None,
|
|
421
|
+
user_email: Optional[str] = None,
|
|
422
|
+
page_size: Optional[int] = None,
|
|
423
|
+
page_number: Optional[int] = None,
|
|
424
|
+
api_key_type: Optional[str] = None,
|
|
425
|
+
):
|
|
426
|
+
return self.auth.fetch_archived_api_keys(
|
|
427
|
+
org_id, user_id, user_email, page_size, page_number, api_key_type
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
def create_api_key(
|
|
431
|
+
self,
|
|
432
|
+
org_id: Optional[str] = None,
|
|
433
|
+
user_id: Optional[str] = None,
|
|
434
|
+
expires_at_seconds: Optional[str] = None,
|
|
435
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
436
|
+
display_name: Optional[str] = None,
|
|
437
|
+
):
|
|
438
|
+
return self.auth.create_api_key(org_id, user_id, expires_at_seconds, metadata, display_name)
|
|
439
|
+
|
|
440
|
+
def update_api_key(self, api_key_id: str, expires_at_seconds: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None, set_to_never_expire: Optional[bool] = None):
|
|
441
|
+
return self.auth.update_api_key(api_key_id, expires_at_seconds, metadata, set_to_never_expire)
|
|
442
|
+
|
|
443
|
+
def delete_api_key(self, api_key_id: str):
|
|
444
|
+
return self.auth.delete_api_key(api_key_id)
|
|
445
|
+
|
|
446
|
+
def validate_personal_api_key(self, api_key_token: str):
|
|
447
|
+
return self.auth.validate_personal_api_key(api_key_token)
|
|
448
|
+
|
|
449
|
+
def validate_org_api_key(self, api_key_token: str):
|
|
450
|
+
return self.auth.validate_org_api_key(api_key_token)
|
|
451
|
+
|
|
452
|
+
def validate_api_key(self, api_key_token: str):
|
|
453
|
+
return self.auth.validate_api_key(api_key_token)
|
|
454
|
+
|
|
455
|
+
def fetch_saml_sp_metadata(self, org_id: str):
|
|
456
|
+
return self.auth.fetch_saml_sp_metadata(org_id)
|
|
457
|
+
|
|
458
|
+
def set_saml_idp_metadata(self, org_id: str, saml_idp_metadata: SamlIdpMetadata):
|
|
459
|
+
return self.auth.set_saml_idp_metadata(org_id=org_id, saml_idp_metadata=saml_idp_metadata)
|
|
460
|
+
|
|
461
|
+
def set_oidc_idp_metadata(self, request: SetOidcIdpMetadataRequest):
|
|
462
|
+
return self.auth.set_oidc_idp_metadata(request)
|
|
463
|
+
|
|
464
|
+
def saml_go_live(self, org_id: str):
|
|
465
|
+
return self.auth.saml_go_live(org_id)
|
|
466
|
+
|
|
467
|
+
def delete_saml_connection(self, org_id: str):
|
|
468
|
+
return self.auth.delete_saml_connection(org_id)
|
|
469
|
+
|
|
470
|
+
def verify_step_up_totp_challenge(
|
|
471
|
+
self,
|
|
472
|
+
action_type: str,
|
|
473
|
+
user_id: str,
|
|
474
|
+
code: str,
|
|
475
|
+
grant_type: StepUpMfaGrantType,
|
|
476
|
+
valid_for_seconds: int,
|
|
477
|
+
) -> StepUpMfaVerifyTotpResponse:
|
|
478
|
+
return self.auth.verify_step_up_totp_challenge(
|
|
479
|
+
action_type, user_id, code, grant_type, valid_for_seconds
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
def verify_step_up_grant(self, action_type: str, user_id: str, grant: str) -> bool:
|
|
483
|
+
return self.auth.verify_step_up_grant(action_type, user_id, grant)
|
|
484
|
+
|
|
485
|
+
def fetch_user_mfa_methods(self, user_id: str):
|
|
486
|
+
return self.auth.fetch_user_mfa_methods(user_id)
|
|
487
|
+
|
|
488
|
+
def invite_user_to_org_by_user_id(
|
|
489
|
+
self, user_id: str, org_id: str, role: str, additional_roles: List[str] = []
|
|
490
|
+
):
|
|
491
|
+
return self.auth.invite_user_to_org_by_user_id(
|
|
492
|
+
user_id,
|
|
493
|
+
org_id,
|
|
494
|
+
role,
|
|
495
|
+
additional_roles,
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
def validate_imported_api_key(self, api_key_token: str):
|
|
499
|
+
return self.auth.validate_imported_api_key(api_key_token)
|
|
500
|
+
|
|
501
|
+
def fetch_api_key_usage(
|
|
502
|
+
self,
|
|
503
|
+
date: str,
|
|
504
|
+
org_id: Optional[str] = None,
|
|
505
|
+
user_id: Optional[str] = None,
|
|
506
|
+
api_key_id: Optional[str] = None
|
|
507
|
+
):
|
|
508
|
+
return self.auth.fetch_api_key_usage(
|
|
509
|
+
date, org_id, user_id, api_key_id
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
def import_api_key(
|
|
513
|
+
self,
|
|
514
|
+
api_key_token: str,
|
|
515
|
+
org_id: Optional[str] = None,
|
|
516
|
+
user_id: Optional[str] = None,
|
|
517
|
+
expires_at_seconds: Optional[str] = None,
|
|
518
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
519
|
+
display_name: Optional[str] = None,
|
|
520
|
+
):
|
|
521
|
+
return self.auth.import_api_key(
|
|
522
|
+
api_key_token,
|
|
523
|
+
org_id,
|
|
524
|
+
user_id,
|
|
525
|
+
expires_at_seconds,
|
|
526
|
+
metadata,
|
|
527
|
+
display_name,
|
|
528
|
+
)
|
|
529
|
+
|
|
530
|
+
def send_sms_mfa_code(
|
|
531
|
+
self,
|
|
532
|
+
action_type: str,
|
|
533
|
+
user_id: str,
|
|
534
|
+
mfa_phone_id: str,
|
|
535
|
+
grant_type: StepUpMfaGrantType,
|
|
536
|
+
valid_for_seconds: int,
|
|
537
|
+
):
|
|
538
|
+
return self.auth.send_sms_mfa_code(
|
|
539
|
+
action_type,
|
|
540
|
+
user_id,
|
|
541
|
+
mfa_phone_id,
|
|
542
|
+
grant_type,
|
|
543
|
+
valid_for_seconds
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
def verify_sms_challenge(
|
|
547
|
+
self,
|
|
548
|
+
challenge_id: str,
|
|
549
|
+
user_id: str,
|
|
550
|
+
code: str,
|
|
551
|
+
):
|
|
552
|
+
return self.auth.verify_sms_challenge(
|
|
553
|
+
challenge_id,
|
|
554
|
+
user_id,
|
|
555
|
+
code
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
# User Insights Reports APIs
|
|
559
|
+
|
|
560
|
+
def fetch_user_top_inviter_report(
|
|
561
|
+
self,
|
|
562
|
+
report_interval: Optional[TopInviterReportInterval] = None,
|
|
563
|
+
page_size: Optional[int] = None,
|
|
564
|
+
page_number: Optional[int] = None,
|
|
565
|
+
) -> UserReport:
|
|
566
|
+
return self.auth.fetch_user_report(
|
|
567
|
+
UserReportType.TOP_INVITERS,
|
|
568
|
+
report_interval,
|
|
569
|
+
page_size,
|
|
570
|
+
page_number
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
def fetch_user_champion_report(
|
|
574
|
+
self,
|
|
575
|
+
report_interval: Optional[ChampionReportInterval] = None,
|
|
576
|
+
page_size: Optional[int] = None,
|
|
577
|
+
page_number: Optional[int] = None,
|
|
578
|
+
) -> UserReport:
|
|
579
|
+
return self.auth.fetch_user_report(
|
|
580
|
+
UserReportType.CHAMPION,
|
|
581
|
+
report_interval,
|
|
582
|
+
page_size,
|
|
583
|
+
page_number
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
def fetch_user_churn_report(
|
|
587
|
+
self,
|
|
588
|
+
report_interval: Optional[ChurnReportInterval] = None,
|
|
589
|
+
page_size: Optional[int] = None,
|
|
590
|
+
page_number: Optional[int] = None,
|
|
591
|
+
) -> UserReport:
|
|
592
|
+
return self.auth.fetch_user_report(
|
|
593
|
+
UserReportType.CHURN,
|
|
594
|
+
report_interval,
|
|
595
|
+
page_size,
|
|
596
|
+
page_number
|
|
597
|
+
)
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
def fetch_user_reengagement_report(
|
|
601
|
+
self,
|
|
602
|
+
report_interval: Optional[ReengagementReportInterval] = None,
|
|
603
|
+
page_size: Optional[int] = None,
|
|
604
|
+
page_number: Optional[int] = None,
|
|
605
|
+
) -> UserReport:
|
|
606
|
+
return self.auth.fetch_user_report(
|
|
607
|
+
UserReportType.REENGAGEMENT,
|
|
608
|
+
report_interval,
|
|
609
|
+
page_size,
|
|
610
|
+
page_number
|
|
611
|
+
)
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
def fetch_org_churn_report(
|
|
615
|
+
self,
|
|
616
|
+
report_interval: Optional[ChurnReportInterval] = None,
|
|
617
|
+
page_size: Optional[int] = None,
|
|
618
|
+
page_number: Optional[int] = None,
|
|
619
|
+
) -> OrgReport:
|
|
620
|
+
return self.auth.fetch_org_report(
|
|
621
|
+
OrgReportType.CHURN,
|
|
622
|
+
report_interval,
|
|
623
|
+
page_size,
|
|
624
|
+
page_number
|
|
625
|
+
)
|
|
626
|
+
|
|
627
|
+
def fetch_org_reengagement_report(
|
|
628
|
+
self,
|
|
629
|
+
report_interval: Optional[ReengagementReportInterval] = None,
|
|
630
|
+
page_size: Optional[int] = None,
|
|
631
|
+
page_number: Optional[int] = None,
|
|
632
|
+
) -> OrgReport:
|
|
633
|
+
return self.auth.fetch_org_report(
|
|
634
|
+
OrgReportType.REENGAGEMENT,
|
|
635
|
+
report_interval,
|
|
636
|
+
page_size,
|
|
637
|
+
page_number
|
|
638
|
+
)
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
def fetch_org_growth_report(
|
|
642
|
+
self,
|
|
643
|
+
report_interval: Optional[GrowthReportInterval] = None,
|
|
644
|
+
page_size: Optional[int] = None,
|
|
645
|
+
page_number: Optional[int] = None,
|
|
646
|
+
) -> OrgReport:
|
|
647
|
+
return self.auth.fetch_org_report(
|
|
648
|
+
OrgReportType.GROWTH,
|
|
649
|
+
report_interval,
|
|
650
|
+
page_size,
|
|
651
|
+
page_number
|
|
652
|
+
)
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
def fetch_org_attrition_report(
|
|
656
|
+
self,
|
|
657
|
+
report_interval: Optional[AttritionReportInterval] = None,
|
|
658
|
+
page_size: Optional[int] = None,
|
|
659
|
+
page_number: Optional[int] = None,
|
|
660
|
+
) -> OrgReport:
|
|
661
|
+
return self.auth.fetch_org_report(
|
|
662
|
+
OrgReportType.ATTRITION,
|
|
663
|
+
report_interval,
|
|
664
|
+
page_size,
|
|
665
|
+
page_number
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
def fetch_chart_metric_data(
|
|
669
|
+
self,
|
|
670
|
+
chart_metric: ChartMetric,
|
|
671
|
+
cadence: Optional[ChartMetricCadence] = None,
|
|
672
|
+
start_date: Optional[date] = None,
|
|
673
|
+
end_date: Optional[date] = None,
|
|
674
|
+
) -> ChartData:
|
|
675
|
+
return self.auth.fetch_chart_metric_data(
|
|
676
|
+
chart_metric,
|
|
677
|
+
cadence,
|
|
678
|
+
start_date,
|
|
679
|
+
end_date
|
|
680
|
+
)
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
def fetch_employee_by_id(self, employee_id: str):
|
|
684
|
+
return self.auth.fetch_employee_by_id(employee_id)
|
|
685
|
+
|
|
686
|
+
def fetch_org_scim_groups(self, org_id: str, user_id: Optional[str] = None, page_size: int = 10, page_number: int = 0):
|
|
687
|
+
return self.auth.fetch_org_scim_groups(
|
|
688
|
+
org_id,
|
|
689
|
+
user_id,
|
|
690
|
+
page_size,
|
|
691
|
+
page_number
|
|
692
|
+
)
|
|
693
|
+
|
|
694
|
+
def fetch_scim_group(
|
|
695
|
+
self,
|
|
696
|
+
org_id: str,
|
|
697
|
+
group_id: str,
|
|
698
|
+
members_page_size: int = 10,
|
|
699
|
+
members_page_number: int = 0,
|
|
700
|
+
):
|
|
701
|
+
return self.auth.fetch_scim_group(
|
|
702
|
+
org_id=org_id,
|
|
703
|
+
group_id=group_id,
|
|
704
|
+
members_page_size=members_page_size,
|
|
705
|
+
members_page_number=members_page_number,
|
|
706
|
+
)
|
|
707
|
+
|
|
708
|
+
def fetch_user_oauth_tokens(self, user_id: str):
|
|
709
|
+
return self.auth.fetch_user_oauth_tokens(user_id)
|
|
710
|
+
|
|
711
|
+
def fetch_fresh_token_from_provider(self, user_id: str, provider: SocialLoginTokenProvider):
|
|
712
|
+
return self.auth.fetch_fresh_token_from_provider(user_id, provider)
|
|
713
|
+
|
|
714
|
+
class FastAPIAuthAsync():
|
|
715
|
+
def __init__(
|
|
716
|
+
self,
|
|
717
|
+
auth_url: str,
|
|
718
|
+
integration_api_key: str,
|
|
719
|
+
token_verification_metadata: Optional[TokenVerificationMetadata],
|
|
720
|
+
debug_mode: bool,
|
|
721
|
+
httpx_client: Optional[httpx.AsyncClient] = None,
|
|
722
|
+
):
|
|
723
|
+
self.auth_url = auth_url
|
|
724
|
+
self.integration_api_key = integration_api_key
|
|
725
|
+
self.token_verification_metadata = token_verification_metadata
|
|
726
|
+
self.debug_mode = debug_mode
|
|
727
|
+
self.httpx_client = httpx_client
|
|
728
|
+
self.auth = init_base_async_auth(auth_url, integration_api_key, token_verification_metadata, self.httpx_client)
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
def require_user(self, credentials: HTTPAuthorizationCredentials = Depends(_security)):
|
|
732
|
+
try:
|
|
733
|
+
# Pass it in to the underlying function to get consistent error messages
|
|
734
|
+
if credentials is None:
|
|
735
|
+
authorization_header = ""
|
|
736
|
+
else:
|
|
737
|
+
authorization_header = (
|
|
738
|
+
credentials.scheme + " " + credentials.credentials
|
|
739
|
+
)
|
|
740
|
+
|
|
741
|
+
user = self.auth.validate_access_token_and_get_user(authorization_header)
|
|
742
|
+
return user
|
|
743
|
+
except UnauthorizedException as e:
|
|
744
|
+
if self.debug_mode:
|
|
745
|
+
raise HTTPException(status_code=401, detail=e.message)
|
|
746
|
+
else:
|
|
747
|
+
raise HTTPException(status_code=401)
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
def optional_user(self, credentials: HTTPAuthorizationCredentials = Depends(_security)):
|
|
751
|
+
if credentials is None:
|
|
752
|
+
return None
|
|
753
|
+
|
|
754
|
+
try:
|
|
755
|
+
authorization_header = credentials.scheme + " " + credentials.credentials
|
|
756
|
+
user = self.auth.validate_access_token_and_get_user(authorization_header)
|
|
757
|
+
return user
|
|
758
|
+
except UnauthorizedException:
|
|
759
|
+
return None
|
|
760
|
+
|
|
761
|
+
def require_org_member(self, user: User, required_org_id: str):
|
|
762
|
+
try:
|
|
763
|
+
return self.auth.validate_org_access_and_get_org(user, required_org_id)
|
|
764
|
+
except ForbiddenException as e:
|
|
765
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
766
|
+
|
|
767
|
+
def require_org_member_with_minimum_role(self, user: User, required_org_id: str, minimum_required_role: str):
|
|
768
|
+
try:
|
|
769
|
+
return self.auth.validate_minimum_org_role_and_get_org(
|
|
770
|
+
user, required_org_id, minimum_required_role
|
|
771
|
+
)
|
|
772
|
+
except ForbiddenException as e:
|
|
773
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
774
|
+
|
|
775
|
+
def require_org_member_with_exact_role(self, user: User, required_org_id: str, role: str):
|
|
776
|
+
try:
|
|
777
|
+
return self.auth.validate_exact_org_role_and_get_org(user, required_org_id, role)
|
|
778
|
+
except ForbiddenException as e:
|
|
779
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
780
|
+
|
|
781
|
+
def require_org_member_with_permission(self, user: User, required_org_id: str, permission: str):
|
|
782
|
+
try:
|
|
783
|
+
return self.auth.validate_permission_and_get_org(
|
|
784
|
+
user, required_org_id, permission
|
|
785
|
+
)
|
|
786
|
+
except ForbiddenException as e:
|
|
787
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
788
|
+
|
|
789
|
+
def require_org_member_with_all_permissions(self, user: User, required_org_id: str, permissions: List[str]):
|
|
790
|
+
try:
|
|
791
|
+
return self.auth.validate_all_permissions_and_get_org(
|
|
792
|
+
user, required_org_id, permissions
|
|
793
|
+
)
|
|
794
|
+
except ForbiddenException as e:
|
|
795
|
+
_handle_forbidden_exception(e, self.debug_mode)
|
|
796
|
+
|
|
797
|
+
def validate_access_token_and_get_user(self, authorization_header: str) -> User:
|
|
798
|
+
return self.auth.validate_access_token_and_get_user(authorization_header=authorization_header)
|
|
799
|
+
|
|
800
|
+
async def fetch_user_metadata_by_user_id(self, user_id: str, include_orgs: bool = False):
|
|
801
|
+
return await self.auth.fetch_user_metadata_by_user_id(user_id, include_orgs)
|
|
802
|
+
|
|
803
|
+
async def fetch_user_metadata_by_email(self, email: str, include_orgs: bool = False):
|
|
804
|
+
return await self.auth.fetch_user_metadata_by_email(email, include_orgs)
|
|
805
|
+
|
|
806
|
+
async def fetch_user_metadata_by_username(self, username: str, include_orgs: bool = False):
|
|
807
|
+
return await self.auth.fetch_user_metadata_by_username(username, include_orgs)
|
|
808
|
+
|
|
809
|
+
async def fetch_user_signup_query_params_by_user_id(self, user_id: str):
|
|
810
|
+
return await self.auth.fetch_user_signup_query_params_by_user_id(user_id)
|
|
811
|
+
|
|
812
|
+
async def fetch_batch_user_metadata_by_user_ids(self, user_ids: List[str], include_orgs: bool = False):
|
|
813
|
+
return await self.auth.fetch_batch_user_metadata_by_user_ids(user_ids, include_orgs)
|
|
814
|
+
|
|
815
|
+
async def fetch_batch_user_metadata_by_emails(self, emails: List[str], include_orgs: bool = False):
|
|
816
|
+
return await self.auth.fetch_batch_user_metadata_by_emails(emails, include_orgs)
|
|
817
|
+
|
|
818
|
+
async def fetch_batch_user_metadata_by_usernames(self, usernames: List[str], include_orgs: bool = False):
|
|
819
|
+
return await self.auth.fetch_batch_user_metadata_by_usernames(usernames, include_orgs)
|
|
820
|
+
|
|
821
|
+
async def fetch_org(self, org_id: str):
|
|
822
|
+
return await self.auth.fetch_org(org_id)
|
|
823
|
+
|
|
824
|
+
async def fetch_org_by_query(
|
|
825
|
+
self, page_size: int = 10, page_number: int = 0, order_by: OrgQueryOrderBy = OrgQueryOrderBy.CREATED_AT_ASC,
|
|
826
|
+
name: Optional[str] = None, legacy_org_id: Optional[str] = None, domain: Optional[str] = None
|
|
827
|
+
):
|
|
828
|
+
return await self.auth.fetch_org_by_query(page_size, page_number, order_by, name, legacy_org_id, domain)
|
|
829
|
+
|
|
830
|
+
async def fetch_custom_role_mappings(self):
|
|
831
|
+
return await self.auth.fetch_custom_role_mappings()
|
|
832
|
+
|
|
833
|
+
async def fetch_pending_invites(self, page_number: int = 0, page_size: int = 10, org_id: Optional[str] = None):
|
|
834
|
+
return await self.auth.fetch_pending_invites(page_number, page_size, org_id)
|
|
835
|
+
|
|
836
|
+
async def fetch_users_by_query(
|
|
837
|
+
self, page_size: int = 10, page_number: int = 0, order_by: UserQueryOrderBy = UserQueryOrderBy.CREATED_AT_ASC,
|
|
838
|
+
email_or_username: Optional[str] = None, include_orgs: bool = False, legacy_user_id: Optional[str] = None
|
|
839
|
+
):
|
|
840
|
+
return await self.auth.fetch_users_by_query(page_size, page_number, order_by, email_or_username, include_orgs, legacy_user_id)
|
|
841
|
+
|
|
842
|
+
async def fetch_users_in_org(
|
|
843
|
+
self, org_id: str, page_size: int = 10, page_number: int = 0, include_orgs: bool = False, role: Optional[str] = None
|
|
844
|
+
):
|
|
845
|
+
return await self.auth.fetch_users_in_org(org_id, page_size, page_number, include_orgs, role)
|
|
846
|
+
|
|
847
|
+
async def create_user(
|
|
848
|
+
self, email: str, email_confirmed: bool = False, send_email_to_confirm_email_address: bool = True,
|
|
849
|
+
ask_user_to_update_password_on_login: bool = False, password: Optional[str] = None, username: Optional[str] = None,
|
|
850
|
+
first_name: Optional[str] = None, last_name: Optional[str] = None, properties: Optional[Dict[str, Any]] = None, ignore_domain_restrictions: bool = False
|
|
851
|
+
):
|
|
852
|
+
return await self.auth.create_user(
|
|
853
|
+
email, email_confirmed, send_email_to_confirm_email_address, ask_user_to_update_password_on_login,
|
|
854
|
+
password, username, first_name, last_name, properties, ignore_domain_restrictions
|
|
855
|
+
)
|
|
856
|
+
|
|
857
|
+
async def invite_user_to_org(self, email: str, org_id: str, role: str, additional_roles: List[str] = []):
|
|
858
|
+
return await self.auth.invite_user_to_org(email, org_id, role, additional_roles)
|
|
859
|
+
|
|
860
|
+
async def resend_email_confirmation(self, user_id: str):
|
|
861
|
+
return await self.auth.resend_email_confirmation(user_id)
|
|
862
|
+
|
|
863
|
+
async def logout_all_user_sessions(self, user_id: str):
|
|
864
|
+
return await self.auth.logout_all_user_sessions(user_id)
|
|
865
|
+
|
|
866
|
+
async def update_user_email(self, user_id: str, new_email: str, require_email_confirmation: bool):
|
|
867
|
+
return await self.auth.update_user_email(user_id, new_email, require_email_confirmation)
|
|
868
|
+
|
|
869
|
+
async def update_user_metadata(
|
|
870
|
+
self,
|
|
871
|
+
user_id: str,
|
|
872
|
+
username: Optional[str] = None,
|
|
873
|
+
first_name: Optional[str] = None,
|
|
874
|
+
last_name: Optional[str] = None,
|
|
875
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
876
|
+
properties: Optional[Dict[str, Any]] = None,
|
|
877
|
+
picture_url: Optional[str] = None,
|
|
878
|
+
update_password_required: Optional[bool] = None,
|
|
879
|
+
legacy_user_id: Optional[str] = None,
|
|
880
|
+
):
|
|
881
|
+
return await self.auth.update_user_metadata(
|
|
882
|
+
user_id, username, first_name, last_name, metadata, properties, picture_url, update_password_required, legacy_user_id
|
|
883
|
+
)
|
|
884
|
+
|
|
885
|
+
async def clear_user_password(self, user_id: str):
|
|
886
|
+
return await self.auth.clear_user_password(user_id)
|
|
887
|
+
|
|
888
|
+
async def update_user_password(self, user_id: str, password: str, ask_user_to_update_password_on_login: bool = False):
|
|
889
|
+
return await self.auth.update_user_password(user_id, password, ask_user_to_update_password_on_login)
|
|
890
|
+
|
|
891
|
+
async def create_magic_link(
|
|
892
|
+
self,
|
|
893
|
+
email: str,
|
|
894
|
+
redirect_to_url: Optional[str] = None,
|
|
895
|
+
expires_in_hours: Optional[int] = None,
|
|
896
|
+
create_new_user_if_one_doesnt_exist: Optional[bool] = None,
|
|
897
|
+
user_signup_query_parameters: Optional[Dict[str, Any]] = None,
|
|
898
|
+
expire_after_first_use: Optional[bool] = None,
|
|
899
|
+
requires_interstitial: Optional[bool] = None,
|
|
900
|
+
):
|
|
901
|
+
return await self.auth.create_magic_link(
|
|
902
|
+
email, redirect_to_url, expires_in_hours, create_new_user_if_one_doesnt_exist, user_signup_query_parameters, expire_after_first_use, requires_interstitial
|
|
903
|
+
)
|
|
904
|
+
|
|
905
|
+
async def create_access_token(self, user_id: str, duration_in_minutes: int, active_org_id: Optional[str] = None):
|
|
906
|
+
return await self.auth.create_access_token(user_id, duration_in_minutes, active_org_id)
|
|
907
|
+
|
|
908
|
+
async def migrate_user_from_external_source(
|
|
909
|
+
self,
|
|
910
|
+
email: str,
|
|
911
|
+
email_confirmed: bool,
|
|
912
|
+
existing_user_id: Optional[str] = None,
|
|
913
|
+
existing_password_hash: Optional[str] = None,
|
|
914
|
+
existing_mfa_base32_encoded_secret: Optional[str] = None,
|
|
915
|
+
ask_user_to_update_password_on_login: bool = False,
|
|
916
|
+
enabled: Optional[bool] = None,
|
|
917
|
+
first_name: Optional[str] = None,
|
|
918
|
+
last_name: Optional[str] = None,
|
|
919
|
+
username: Optional[str] = None,
|
|
920
|
+
picture_url: Optional[str] = None,
|
|
921
|
+
properties: Optional[Dict[str, Any]] = None,
|
|
922
|
+
):
|
|
923
|
+
return await self.auth.migrate_user_from_external_source(
|
|
924
|
+
email, email_confirmed, existing_user_id, existing_password_hash,
|
|
925
|
+
existing_mfa_base32_encoded_secret, ask_user_to_update_password_on_login,
|
|
926
|
+
enabled, first_name, last_name, username, picture_url, properties
|
|
927
|
+
)
|
|
928
|
+
|
|
929
|
+
async def migrate_user_password(
|
|
930
|
+
self,
|
|
931
|
+
user_id: str,
|
|
932
|
+
password_hash: str,
|
|
933
|
+
):
|
|
934
|
+
return await self.auth.migrate_user_password(user_id, password_hash)
|
|
935
|
+
|
|
936
|
+
async def create_org(
|
|
937
|
+
self,
|
|
938
|
+
name: str,
|
|
939
|
+
enable_auto_joining_by_domain: bool = False,
|
|
940
|
+
members_must_have_matching_domain: bool = False,
|
|
941
|
+
domain: Optional[str] = None,
|
|
942
|
+
max_users: Optional[str] = None,
|
|
943
|
+
custom_role_mapping_name: Optional[str] = None,
|
|
944
|
+
legacy_org_id: Optional[str] = None,
|
|
945
|
+
):
|
|
946
|
+
return await self.auth.create_org(
|
|
947
|
+
name, enable_auto_joining_by_domain, members_must_have_matching_domain,
|
|
948
|
+
domain, max_users, custom_role_mapping_name, legacy_org_id
|
|
949
|
+
)
|
|
950
|
+
|
|
951
|
+
async def update_org_metadata(
|
|
952
|
+
self,
|
|
953
|
+
org_id: str,
|
|
954
|
+
name: Optional[str] = None,
|
|
955
|
+
can_setup_saml: Optional[bool] = None,
|
|
956
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
957
|
+
max_users: Optional[str] = None,
|
|
958
|
+
can_join_on_email_domain_match: Optional[bool] = None,
|
|
959
|
+
members_must_have_email_domain_match: Optional[bool] = None,
|
|
960
|
+
domain: Optional[str] = None,
|
|
961
|
+
require_2fa_by: Optional[str] = None,
|
|
962
|
+
extra_domains: Optional[List[str]] = None,
|
|
963
|
+
password_rotation_enabled: Optional[bool] = None,
|
|
964
|
+
password_rotation_history_size: Optional[int] = None,
|
|
965
|
+
password_rotation_period: Optional[int] = None,
|
|
966
|
+
):
|
|
967
|
+
return await self.auth.update_org_metadata(
|
|
968
|
+
org_id, name, can_setup_saml, metadata, max_users,
|
|
969
|
+
can_join_on_email_domain_match, members_must_have_email_domain_match, domain, require_2fa_by, extra_domains, password_rotation_enabled, password_rotation_history_size, password_rotation_period
|
|
970
|
+
)
|
|
971
|
+
|
|
972
|
+
async def subscribe_org_to_role_mapping(self, org_id: str, custom_role_mapping_name: str):
|
|
973
|
+
return await self.auth.subscribe_org_to_role_mapping(org_id, custom_role_mapping_name)
|
|
974
|
+
|
|
975
|
+
async def delete_org(self, org_id: str):
|
|
976
|
+
return await self.auth.delete_org(org_id)
|
|
977
|
+
|
|
978
|
+
async def revoke_pending_org_invite(self, org_id: str, invitee_email: str):
|
|
979
|
+
return await self.auth.revoke_pending_org_invite(org_id, invitee_email)
|
|
980
|
+
|
|
981
|
+
async def add_user_to_org(self, user_id: str, org_id: str, role: str, additional_roles: List[str] = []):
|
|
982
|
+
return await self.auth.add_user_to_org(user_id, org_id, role, additional_roles)
|
|
983
|
+
|
|
984
|
+
async def remove_user_from_org(self, user_id: str, org_id: str):
|
|
985
|
+
return await self.auth.remove_user_from_org(user_id, org_id)
|
|
986
|
+
|
|
987
|
+
async def change_user_role_in_org(self, user_id: str, org_id: str, role: str, additional_roles: List[str] = []):
|
|
988
|
+
return await self.auth.change_user_role_in_org(user_id, org_id, role, additional_roles)
|
|
989
|
+
|
|
990
|
+
async def delete_user(self, user_id: str):
|
|
991
|
+
return await self.auth.delete_user(user_id)
|
|
992
|
+
|
|
993
|
+
async def disable_user(self, user_id: str):
|
|
994
|
+
return await self.auth.disable_user(user_id)
|
|
995
|
+
|
|
996
|
+
async def enable_user(self, user_id: str):
|
|
997
|
+
return await self.auth.enable_user(user_id)
|
|
998
|
+
|
|
999
|
+
async def disable_user_2fa(self, user_id: str):
|
|
1000
|
+
return await self.auth.disable_user_2fa(user_id)
|
|
1001
|
+
|
|
1002
|
+
async def enable_user_can_create_orgs(self, user_id: str):
|
|
1003
|
+
return await self.auth.enable_user_can_create_orgs(user_id)
|
|
1004
|
+
|
|
1005
|
+
async def disable_user_can_create_orgs(self, user_id: str):
|
|
1006
|
+
return await self.auth.disable_user_can_create_orgs(user_id)
|
|
1007
|
+
|
|
1008
|
+
async def allow_org_to_setup_saml_connection(self, org_id: str):
|
|
1009
|
+
return await self.auth.allow_org_to_setup_saml_connection(org_id)
|
|
1010
|
+
|
|
1011
|
+
async def disallow_org_to_setup_saml_connection(self, org_id: str):
|
|
1012
|
+
return await self.auth.disallow_org_to_setup_saml_connection(org_id)
|
|
1013
|
+
|
|
1014
|
+
async def fetch_api_key(self, api_key_id: str):
|
|
1015
|
+
return await self.auth.fetch_api_key(api_key_id)
|
|
1016
|
+
|
|
1017
|
+
async def fetch_current_api_keys(
|
|
1018
|
+
self,
|
|
1019
|
+
org_id: Optional[str] = None,
|
|
1020
|
+
user_id: Optional[str] = None,
|
|
1021
|
+
user_email: Optional[str] = None,
|
|
1022
|
+
page_size: Optional[int] = None,
|
|
1023
|
+
page_number: Optional[int] = None,
|
|
1024
|
+
api_key_type: Optional[str] = None,
|
|
1025
|
+
):
|
|
1026
|
+
return await self.auth.fetch_current_api_keys(
|
|
1027
|
+
org_id, user_id, user_email, page_size, page_number, api_key_type
|
|
1028
|
+
)
|
|
1029
|
+
|
|
1030
|
+
async def fetch_archived_api_keys(
|
|
1031
|
+
self,
|
|
1032
|
+
org_id: Optional[str] = None,
|
|
1033
|
+
user_id: Optional[str] = None,
|
|
1034
|
+
user_email: Optional[str] = None,
|
|
1035
|
+
page_size: Optional[int] = None,
|
|
1036
|
+
page_number: Optional[int] = None,
|
|
1037
|
+
api_key_type: Optional[str] = None,
|
|
1038
|
+
):
|
|
1039
|
+
return await self.auth.fetch_archived_api_keys(
|
|
1040
|
+
org_id, user_id, user_email, page_size, page_number, api_key_type
|
|
1041
|
+
)
|
|
1042
|
+
|
|
1043
|
+
async def create_api_key(
|
|
1044
|
+
self,
|
|
1045
|
+
org_id: Optional[str] = None,
|
|
1046
|
+
user_id: Optional[str] = None,
|
|
1047
|
+
expires_at_seconds: Optional[str] = None,
|
|
1048
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
1049
|
+
display_name: Optional[str] = None,
|
|
1050
|
+
):
|
|
1051
|
+
return await self.auth.create_api_key(org_id, user_id, expires_at_seconds, metadata, display_name)
|
|
1052
|
+
|
|
1053
|
+
async def update_api_key(self, api_key_id: str, expires_at_seconds: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None, set_to_never_expire: Optional[bool] = None):
|
|
1054
|
+
return await self.auth.update_api_key(api_key_id, expires_at_seconds, metadata, set_to_never_expire)
|
|
1055
|
+
|
|
1056
|
+
async def delete_api_key(self, api_key_id: str):
|
|
1057
|
+
return await self.auth.delete_api_key(api_key_id)
|
|
1058
|
+
|
|
1059
|
+
async def validate_personal_api_key(self, api_key_token: str):
|
|
1060
|
+
return await self.auth.validate_personal_api_key(api_key_token)
|
|
1061
|
+
|
|
1062
|
+
async def validate_org_api_key(self, api_key_token: str):
|
|
1063
|
+
return await self.auth.validate_org_api_key(api_key_token)
|
|
1064
|
+
|
|
1065
|
+
async def validate_api_key(self, api_key_token: str):
|
|
1066
|
+
return await self.auth.validate_api_key(api_key_token)
|
|
1067
|
+
|
|
1068
|
+
async def fetch_saml_sp_metadata(self, org_id: str):
|
|
1069
|
+
return await self.auth.fetch_saml_sp_metadata(org_id)
|
|
1070
|
+
|
|
1071
|
+
async def set_saml_idp_metadata(self, org_id: str, saml_idp_metadata: SamlIdpMetadata):
|
|
1072
|
+
return await self.auth.set_saml_idp_metadata(org_id=org_id, saml_idp_metadata=saml_idp_metadata)
|
|
1073
|
+
|
|
1074
|
+
async def set_oidc_idp_metadata(self, request: SetOidcIdpMetadataRequest):
|
|
1075
|
+
return await self.auth.set_oidc_idp_metadata(request)
|
|
1076
|
+
|
|
1077
|
+
async def saml_go_live(self, org_id: str):
|
|
1078
|
+
return await self.auth.saml_go_live(org_id)
|
|
1079
|
+
|
|
1080
|
+
async def delete_saml_connection(self, org_id: str):
|
|
1081
|
+
return await self.auth.delete_saml_connection(org_id)
|
|
1082
|
+
|
|
1083
|
+
async def verify_step_up_totp_challenge(
|
|
1084
|
+
self,
|
|
1085
|
+
action_type: str,
|
|
1086
|
+
user_id: str,
|
|
1087
|
+
code: str,
|
|
1088
|
+
grant_type: StepUpMfaGrantType,
|
|
1089
|
+
valid_for_seconds: int,
|
|
1090
|
+
) -> StepUpMfaVerifyTotpResponse:
|
|
1091
|
+
return await self.auth.verify_step_up_totp_challenge(
|
|
1092
|
+
action_type, user_id, code, grant_type, valid_for_seconds
|
|
1093
|
+
)
|
|
1094
|
+
|
|
1095
|
+
async def verify_step_up_grant(self, action_type: str, user_id: str, grant: str) -> bool:
|
|
1096
|
+
return await self.auth.verify_step_up_grant(action_type, user_id, grant)
|
|
1097
|
+
|
|
1098
|
+
async def validate_imported_api_key(self, api_key_token: str):
|
|
1099
|
+
return await self.auth.validate_imported_api_key(
|
|
1100
|
+
api_key_token=api_key_token
|
|
1101
|
+
)
|
|
1102
|
+
|
|
1103
|
+
async def fetch_api_key_usage(
|
|
1104
|
+
self,
|
|
1105
|
+
date: str,
|
|
1106
|
+
org_id: Optional[str] = None,
|
|
1107
|
+
user_id: Optional[str] = None,
|
|
1108
|
+
api_key_id: Optional[str] = None
|
|
1109
|
+
):
|
|
1110
|
+
return await self.auth.fetch_api_key_usage(
|
|
1111
|
+
date,
|
|
1112
|
+
org_id,
|
|
1113
|
+
user_id,
|
|
1114
|
+
api_key_id
|
|
1115
|
+
)
|
|
1116
|
+
|
|
1117
|
+
async def import_api_key(
|
|
1118
|
+
self,
|
|
1119
|
+
api_key_token: str,
|
|
1120
|
+
org_id: Optional[str] = None,
|
|
1121
|
+
user_id: Optional[str] = None,
|
|
1122
|
+
expires_at_seconds: Optional[str] = None,
|
|
1123
|
+
metadata: Optional[Dict[str, Any]] = None,
|
|
1124
|
+
display_name: Optional[str] = None,
|
|
1125
|
+
):
|
|
1126
|
+
return await self.auth.import_api_key(
|
|
1127
|
+
api_key_token,
|
|
1128
|
+
org_id,
|
|
1129
|
+
user_id,
|
|
1130
|
+
expires_at_seconds,
|
|
1131
|
+
metadata,
|
|
1132
|
+
display_name
|
|
1133
|
+
)
|
|
1134
|
+
|
|
1135
|
+
async def invite_user_to_org_by_user_id(
|
|
1136
|
+
self,
|
|
1137
|
+
user_id: str,
|
|
1138
|
+
org_id: str,
|
|
1139
|
+
role: str,
|
|
1140
|
+
additional_roles: List[str] = []
|
|
1141
|
+
):
|
|
1142
|
+
return await self.auth.invite_user_to_org_by_user_id(
|
|
1143
|
+
user_id,
|
|
1144
|
+
org_id,
|
|
1145
|
+
role,
|
|
1146
|
+
additional_roles,
|
|
1147
|
+
)
|
|
1148
|
+
|
|
1149
|
+
async def fetch_user_mfa_methods(self, user_id: str):
|
|
1150
|
+
return await self.auth.fetch_user_mfa_methods(
|
|
1151
|
+
user_id,
|
|
1152
|
+
)
|
|
1153
|
+
|
|
1154
|
+
async def send_sms_mfa_code(
|
|
1155
|
+
self,
|
|
1156
|
+
action_type: str,
|
|
1157
|
+
user_id: str,
|
|
1158
|
+
mfa_phone_id: str,
|
|
1159
|
+
grant_type: StepUpMfaGrantType,
|
|
1160
|
+
valid_for_seconds: int,
|
|
1161
|
+
):
|
|
1162
|
+
return await self.auth.send_sms_mfa_code(
|
|
1163
|
+
action_type,
|
|
1164
|
+
user_id,
|
|
1165
|
+
mfa_phone_id,
|
|
1166
|
+
grant_type,
|
|
1167
|
+
valid_for_seconds
|
|
1168
|
+
)
|
|
1169
|
+
|
|
1170
|
+
async def verify_sms_challenge(
|
|
1171
|
+
self,
|
|
1172
|
+
challenge_id: str,
|
|
1173
|
+
user_id: str,
|
|
1174
|
+
code: str,
|
|
1175
|
+
):
|
|
1176
|
+
return await self.auth.verify_sms_challenge(
|
|
1177
|
+
challenge_id,
|
|
1178
|
+
user_id,
|
|
1179
|
+
code
|
|
1180
|
+
)
|
|
1181
|
+
|
|
1182
|
+
# User Insights Reports APIs
|
|
1183
|
+
|
|
1184
|
+
async def fetch_user_top_inviter_report(
|
|
1185
|
+
self,
|
|
1186
|
+
report_interval: Optional[TopInviterReportInterval] = None,
|
|
1187
|
+
page_size: Optional[int] = None,
|
|
1188
|
+
page_number: Optional[int] = None,
|
|
1189
|
+
) -> UserReport:
|
|
1190
|
+
return await self.auth.fetch_user_report_async(
|
|
1191
|
+
UserReportType.TOP_INVITERS,
|
|
1192
|
+
report_interval,
|
|
1193
|
+
page_size,
|
|
1194
|
+
page_number
|
|
1195
|
+
)
|
|
1196
|
+
|
|
1197
|
+
async def fetch_user_champion_report(
|
|
1198
|
+
self,
|
|
1199
|
+
report_interval: Optional[ChampionReportInterval] = None,
|
|
1200
|
+
page_size: Optional[int] = None,
|
|
1201
|
+
page_number: Optional[int] = None,
|
|
1202
|
+
) -> UserReport:
|
|
1203
|
+
return await self.auth.fetch_user_report_async(
|
|
1204
|
+
UserReportType.CHAMPION,
|
|
1205
|
+
report_interval,
|
|
1206
|
+
page_size,
|
|
1207
|
+
page_number
|
|
1208
|
+
)
|
|
1209
|
+
|
|
1210
|
+
async def fetch_user_churn_report(
|
|
1211
|
+
self,
|
|
1212
|
+
report_interval: Optional[ChurnReportInterval] = None,
|
|
1213
|
+
page_size: Optional[int] = None,
|
|
1214
|
+
page_number: Optional[int] = None,
|
|
1215
|
+
) -> UserReport:
|
|
1216
|
+
return await self.auth.fetch_user_report_async(
|
|
1217
|
+
UserReportType.CHURN,
|
|
1218
|
+
report_interval,
|
|
1219
|
+
page_size,
|
|
1220
|
+
page_number
|
|
1221
|
+
)
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
async def fetch_user_reengagement_report(
|
|
1225
|
+
self,
|
|
1226
|
+
report_interval: Optional[ReengagementReportInterval] = None,
|
|
1227
|
+
page_size: Optional[int] = None,
|
|
1228
|
+
page_number: Optional[int] = None,
|
|
1229
|
+
) -> UserReport:
|
|
1230
|
+
return await self.auth.fetch_user_report_async(
|
|
1231
|
+
UserReportType.REENGAGEMENT,
|
|
1232
|
+
report_interval,
|
|
1233
|
+
page_size,
|
|
1234
|
+
page_number
|
|
1235
|
+
)
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
async def fetch_org_churn_report(
|
|
1239
|
+
self,
|
|
1240
|
+
report_interval: Optional[ChurnReportInterval] = None,
|
|
1241
|
+
page_size: Optional[int] = None,
|
|
1242
|
+
page_number: Optional[int] = None,
|
|
1243
|
+
) -> OrgReport:
|
|
1244
|
+
return await self.auth.fetch_org_report_async(
|
|
1245
|
+
OrgReportType.CHURN,
|
|
1246
|
+
report_interval,
|
|
1247
|
+
page_size,
|
|
1248
|
+
page_number
|
|
1249
|
+
)
|
|
1250
|
+
|
|
1251
|
+
async def fetch_org_reengagement_report(
|
|
1252
|
+
self,
|
|
1253
|
+
report_interval: Optional[ReengagementReportInterval] = None,
|
|
1254
|
+
page_size: Optional[int] = None,
|
|
1255
|
+
page_number: Optional[int] = None,
|
|
1256
|
+
) -> OrgReport:
|
|
1257
|
+
return await self.auth.fetch_org_report_async(
|
|
1258
|
+
OrgReportType.REENGAGEMENT,
|
|
1259
|
+
report_interval,
|
|
1260
|
+
page_size,
|
|
1261
|
+
page_number
|
|
1262
|
+
)
|
|
1263
|
+
|
|
1264
|
+
|
|
1265
|
+
async def fetch_org_growth_report(
|
|
1266
|
+
self,
|
|
1267
|
+
report_interval: Optional[GrowthReportInterval] = None,
|
|
1268
|
+
page_size: Optional[int] = None,
|
|
1269
|
+
page_number: Optional[int] = None,
|
|
1270
|
+
) -> OrgReport:
|
|
1271
|
+
return await self.auth.fetch_org_report_async(
|
|
1272
|
+
OrgReportType.GROWTH,
|
|
1273
|
+
report_interval,
|
|
1274
|
+
page_size,
|
|
1275
|
+
page_number
|
|
1276
|
+
)
|
|
1277
|
+
|
|
1278
|
+
|
|
1279
|
+
async def fetch_org_attrition_report(
|
|
1280
|
+
self,
|
|
1281
|
+
report_interval: Optional[AttritionReportInterval] = None,
|
|
1282
|
+
page_size: Optional[int] = None,
|
|
1283
|
+
page_number: Optional[int] = None,
|
|
1284
|
+
) -> OrgReport:
|
|
1285
|
+
return await self.auth.fetch_org_report_async(
|
|
1286
|
+
OrgReportType.ATTRITION,
|
|
1287
|
+
report_interval,
|
|
1288
|
+
page_size,
|
|
1289
|
+
page_number
|
|
1290
|
+
)
|
|
1291
|
+
|
|
1292
|
+
async def fetch_chart_metric_data(
|
|
1293
|
+
self,
|
|
1294
|
+
chart_metric: ChartMetric,
|
|
1295
|
+
cadence: Optional[ChartMetricCadence] = None,
|
|
1296
|
+
start_date: Optional[date] = None,
|
|
1297
|
+
end_date: Optional[date] = None,
|
|
1298
|
+
) -> ChartData:
|
|
1299
|
+
return await self.auth.fetch_chart_metric_data_async(
|
|
1300
|
+
chart_metric,
|
|
1301
|
+
cadence,
|
|
1302
|
+
start_date,
|
|
1303
|
+
end_date
|
|
1304
|
+
)
|
|
1305
|
+
|
|
1306
|
+
async def fetch_employee_by_id(self, employee_id: str):
|
|
1307
|
+
return await self.auth.fetch_employee_by_id(
|
|
1308
|
+
employee_id
|
|
1309
|
+
)
|
|
1310
|
+
|
|
1311
|
+
async def fetch_org_scim_groups(self, org_id: str, user_id: Optional[str] = None, page_size: int = 10, page_number: int = 0):
|
|
1312
|
+
return await self.auth.fetch_org_scim_groups(
|
|
1313
|
+
org_id,
|
|
1314
|
+
user_id,
|
|
1315
|
+
page_size,
|
|
1316
|
+
page_number
|
|
1317
|
+
)
|
|
1318
|
+
|
|
1319
|
+
async def fetch_scim_group(
|
|
1320
|
+
self,
|
|
1321
|
+
org_id: str,
|
|
1322
|
+
group_id: str,
|
|
1323
|
+
members_page_size: int = 10,
|
|
1324
|
+
members_page_number: int = 0,
|
|
1325
|
+
):
|
|
1326
|
+
return await self.auth.fetch_scim_group(
|
|
1327
|
+
org_id=org_id,
|
|
1328
|
+
group_id=group_id,
|
|
1329
|
+
members_page_size=members_page_size,
|
|
1330
|
+
members_page_number=members_page_number,
|
|
1331
|
+
)
|
|
1332
|
+
|
|
1333
|
+
async def fetch_user_oauth_tokens(self, user_id: str):
|
|
1334
|
+
return await self.auth.fetch_user_oauth_tokens(user_id)
|
|
1335
|
+
|
|
1336
|
+
async def fetch_fresh_token_from_provider(self, user_id: str, provider: SocialLoginTokenProvider):
|
|
1337
|
+
return await self.auth.fetch_fresh_token_from_provider(user_id, provider)
|
|
1338
|
+
|
|
1339
|
+
|
|
1340
|
+
def init_auth(
|
|
1341
|
+
auth_url: str,
|
|
1342
|
+
api_key: str,
|
|
1343
|
+
token_verification_metadata: Optional[TokenVerificationMetadata] = None,
|
|
1344
|
+
debug_mode: bool = False,
|
|
1345
|
+
log_exceptions: bool = False,
|
|
1346
|
+
) -> FastAPIAuth:
|
|
1347
|
+
configure_logging(log_exceptions)
|
|
1348
|
+
|
|
1349
|
+
"""Fetches metadata required to validate access tokens and returns auth decorators and utilities"""
|
|
1350
|
+
return FastAPIAuth(auth_url=auth_url, integration_api_key=api_key, token_verification_metadata=token_verification_metadata, debug_mode=debug_mode)
|
|
1351
|
+
|
|
1352
|
+
def init_auth_async(
|
|
1353
|
+
auth_url: str,
|
|
1354
|
+
api_key: str,
|
|
1355
|
+
token_verification_metadata: Optional[TokenVerificationMetadata] = None,
|
|
1356
|
+
debug_mode=False,
|
|
1357
|
+
httpx_client: Optional[httpx.AsyncClient] = None,
|
|
1358
|
+
log_exceptions: bool = False,
|
|
1359
|
+
) -> FastAPIAuthAsync:
|
|
1360
|
+
configure_logging(log_exceptions)
|
|
1361
|
+
|
|
1362
|
+
"""Fetches metadata required to validate access tokens and returns auth decorators and utilities"""
|
|
1363
|
+
return FastAPIAuthAsync(auth_url=auth_url, integration_api_key=api_key, token_verification_metadata=token_verification_metadata, debug_mode=debug_mode, httpx_client=httpx_client)
|