| 1 |
|
| 2 |
|
| 3 |
import typing |
| 4 |
|
| 5 |
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 6 |
from ...core.pagination import AsyncPager, SyncPager |
| 7 |
from ...core.request_options import RequestOptions |
| 8 |
from ...types.list_role_users_paginated_response_content import ListRoleUsersPaginatedResponseContent |
| 9 |
from ...types.role_user import RoleUser |
| 10 |
from .raw_client import AsyncRawUsersClient, RawUsersClient |
| 11 |
|
| 12 |
|
| 13 |
OMIT = typing.cast(typing.Any, ...) |
| 14 |
|
| 15 |
|
| 16 |
class UsersClient: |
| 17 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 18 |
self._raw_client = RawUsersClient(client_wrapper=client_wrapper) |
| 19 |
|
| 20 |
@property |
| 21 |
def with_raw_response(self) -> RawUsersClient: |
| 22 |
""" |
| 23 |
Retrieves a raw implementation of this client that returns raw responses. |
| 24 |
|
| 25 |
Returns |
| 26 |
------- |
| 27 |
RawUsersClient |
| 28 |
""" |
| 29 |
return self._raw_client |
| 30 |
|
| 31 |
def list( |
| 32 |
self, |
| 33 |
id: str, |
| 34 |
*, |
| 35 |
from_: typing.Optional[str] = None, |
| 36 |
take: typing.Optional[int] = 50, |
| 37 |
request_options: typing.Optional[RequestOptions] = None, |
| 38 |
) -> SyncPager[RoleUser, ListRoleUsersPaginatedResponseContent]: |
| 39 |
""" |
| 40 |
Retrieve list of users associated with a specific role. For Dashboard instructions, review [View Users Assigned to Roles](https://auth0.com/docs/manage-users/access-control/configure-core-rbac/roles/view-users-assigned-to-roles). |
| 41 |
|
| 42 |
This endpoint supports two types of pagination: |
| 43 |
|
| 44 |
- Offset pagination |
| 45 |
- Checkpoint pagination |
| 46 |
|
| 47 |
Checkpoint pagination must be used if you need to retrieve more than 1000 organization members. |
| 48 |
|
| 49 |
**Checkpoint Pagination** |
| 50 |
|
| 51 |
To search by checkpoint, use the following parameters: |
| 52 |
|
| 53 |
- `from`: Optional id from which to start selection. |
| 54 |
- `take`: The total amount of entries to retrieve when using the from parameter. Defaults to 50. |
| 55 |
|
| 56 |
**Note**: The first time you call this endpoint using checkpoint pagination, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no pages are remaining. |
| 57 |
|
| 58 |
Parameters |
| 59 |
---------- |
| 60 |
id : str |
| 61 |
ID of the role to retrieve a list of users associated with. |
| 62 |
|
| 63 |
from_ : typing.Optional[str] |
| 64 |
Optional Id from which to start selection. |
| 65 |
|
| 66 |
take : typing.Optional[int] |
| 67 |
Number of results per page. Defaults to 50. |
| 68 |
|
| 69 |
request_options : typing.Optional[RequestOptions] |
| 70 |
Request-specific configuration. |
| 71 |
|
| 72 |
Returns |
| 73 |
------- |
| 74 |
SyncPager[RoleUser, ListRoleUsersPaginatedResponseContent] |
| 75 |
Role users successfully retrieved. |
| 76 |
|
| 77 |
Examples |
| 78 |
-------- |
| 79 |
from auth0 import Auth0 |
| 80 |
|
| 81 |
client = Auth0( |
| 82 |
token="YOUR_TOKEN", |
| 83 |
) |
| 84 |
response = client.roles.users.list( |
| 85 |
id="id", |
| 86 |
from_="from", |
| 87 |
take=1, |
| 88 |
) |
| 89 |
for item in response: |
| 90 |
yield item |
| 91 |
# alternatively, you can paginate page-by-page |
| 92 |
for page in response.iter_pages(): |
| 93 |
yield page |
| 94 |
""" |
| 95 |
return self._raw_client.list(id, from_=from_, take=take, request_options=request_options) |
| 96 |
|
| 97 |
def assign( |
| 98 |
self, id: str, *, users: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None |
| 99 |
) -> None: |
| 100 |
""" |
| 101 |
Assign one or more users to an existing user role. To learn more, review [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac). |
| 102 |
|
| 103 |
**Note**: New roles cannot be created through this action. |
| 104 |
|
| 105 |
Parameters |
| 106 |
---------- |
| 107 |
id : str |
| 108 |
ID of the role to assign users to. |
| 109 |
|
| 110 |
users : typing.Sequence[str] |
| 111 |
user_id's of the users to assign the role to. |
| 112 |
|
| 113 |
request_options : typing.Optional[RequestOptions] |
| 114 |
Request-specific configuration. |
| 115 |
|
| 116 |
Returns |
| 117 |
------- |
| 118 |
None |
| 119 |
|
| 120 |
Examples |
| 121 |
-------- |
| 122 |
from auth0 import Auth0 |
| 123 |
|
| 124 |
client = Auth0( |
| 125 |
token="YOUR_TOKEN", |
| 126 |
) |
| 127 |
client.roles.users.assign( |
| 128 |
id="id", |
| 129 |
users=["users"], |
| 130 |
) |
| 131 |
""" |
| 132 |
_response = self._raw_client.assign(id, users=users, request_options=request_options) |
| 133 |
return _response.data |
| 134 |
|
| 135 |
|
| 136 |
class AsyncUsersClient: |
| 137 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 138 |
self._raw_client = AsyncRawUsersClient(client_wrapper=client_wrapper) |
| 139 |
|
| 140 |
@property |
| 141 |
def with_raw_response(self) -> AsyncRawUsersClient: |
| 142 |
""" |
| 143 |
Retrieves a raw implementation of this client that returns raw responses. |
| 144 |
|
| 145 |
Returns |
| 146 |
------- |
| 147 |
AsyncRawUsersClient |
| 148 |
""" |
| 149 |
return self._raw_client |
| 150 |
|
| 151 |
async def list( |
| 152 |
self, |
| 153 |
id: str, |
| 154 |
*, |
| 155 |
from_: typing.Optional[str] = None, |
| 156 |
take: typing.Optional[int] = 50, |
| 157 |
request_options: typing.Optional[RequestOptions] = None, |
| 158 |
) -> AsyncPager[RoleUser, ListRoleUsersPaginatedResponseContent]: |
| 159 |
""" |
| 160 |
Retrieve list of users associated with a specific role. For Dashboard instructions, review [View Users Assigned to Roles](https://auth0.com/docs/manage-users/access-control/configure-core-rbac/roles/view-users-assigned-to-roles). |
| 161 |
|
| 162 |
This endpoint supports two types of pagination: |
| 163 |
|
| 164 |
- Offset pagination |
| 165 |
- Checkpoint pagination |
| 166 |
|
| 167 |
Checkpoint pagination must be used if you need to retrieve more than 1000 organization members. |
| 168 |
|
| 169 |
**Checkpoint Pagination** |
| 170 |
|
| 171 |
To search by checkpoint, use the following parameters: |
| 172 |
|
| 173 |
- `from`: Optional id from which to start selection. |
| 174 |
- `take`: The total amount of entries to retrieve when using the from parameter. Defaults to 50. |
| 175 |
|
| 176 |
**Note**: The first time you call this endpoint using checkpoint pagination, omit the `from` parameter. If there are more results, a `next` value is included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, no pages are remaining. |
| 177 |
|
| 178 |
Parameters |
| 179 |
---------- |
| 180 |
id : str |
| 181 |
ID of the role to retrieve a list of users associated with. |
| 182 |
|
| 183 |
from_ : typing.Optional[str] |
| 184 |
Optional Id from which to start selection. |
| 185 |
|
| 186 |
take : typing.Optional[int] |
| 187 |
Number of results per page. Defaults to 50. |
| 188 |
|
| 189 |
request_options : typing.Optional[RequestOptions] |
| 190 |
Request-specific configuration. |
| 191 |
|
| 192 |
Returns |
| 193 |
------- |
| 194 |
AsyncPager[RoleUser, ListRoleUsersPaginatedResponseContent] |
| 195 |
Role users successfully retrieved. |
| 196 |
|
| 197 |
Examples |
| 198 |
-------- |
| 199 |
import asyncio |
| 200 |
|
| 201 |
from auth0 import AsyncAuth0 |
| 202 |
|
| 203 |
client = AsyncAuth0( |
| 204 |
token="YOUR_TOKEN", |
| 205 |
) |
| 206 |
|
| 207 |
|
| 208 |
async def main() -> None: |
| 209 |
response = await client.roles.users.list( |
| 210 |
id="id", |
| 211 |
from_="from", |
| 212 |
take=1, |
| 213 |
) |
| 214 |
async for item in response: |
| 215 |
yield item |
| 216 |
|
| 217 |
# alternatively, you can paginate page-by-page |
| 218 |
async for page in response.iter_pages(): |
| 219 |
yield page |
| 220 |
|
| 221 |
|
| 222 |
asyncio.run(main()) |
| 223 |
""" |
| 224 |
return await self._raw_client.list(id, from_=from_, take=take, request_options=request_options) |
| 225 |
|
| 226 |
async def assign( |
| 227 |
self, id: str, *, users: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None |
| 228 |
) -> None: |
| 229 |
""" |
| 230 |
Assign one or more users to an existing user role. To learn more, review [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac). |
| 231 |
|
| 232 |
**Note**: New roles cannot be created through this action. |
| 233 |
|
| 234 |
Parameters |
| 235 |
---------- |
| 236 |
id : str |
| 237 |
ID of the role to assign users to. |
| 238 |
|
| 239 |
users : typing.Sequence[str] |
| 240 |
user_id's of the users to assign the role to. |
| 241 |
|
| 242 |
request_options : typing.Optional[RequestOptions] |
| 243 |
Request-specific configuration. |
| 244 |
|
| 245 |
Returns |
| 246 |
------- |
| 247 |
None |
| 248 |
|
| 249 |
Examples |
| 250 |
-------- |
| 251 |
import asyncio |
| 252 |
|
| 253 |
from auth0 import AsyncAuth0 |
| 254 |
|
| 255 |
client = AsyncAuth0( |
| 256 |
token="YOUR_TOKEN", |
| 257 |
) |
| 258 |
|
| 259 |
|
| 260 |
async def main() -> None: |
| 261 |
await client.roles.users.assign( |
| 262 |
id="id", |
| 263 |
users=["users"], |
| 264 |
) |
| 265 |
|
| 266 |
|
| 267 |
asyncio.run(main()) |
| 268 |
""" |
| 269 |
_response = await self._raw_client.assign(id, users=users, request_options=request_options) |
| 270 |
return _response.data |