| 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_user_roles_offset_paginated_response_content import ListUserRolesOffsetPaginatedResponseContent |
| 9 |
from ...types.role import Role |
| 10 |
from .raw_client import AsyncRawRolesClient, RawRolesClient |
| 11 |
|
| 12 |
|
| 13 |
OMIT = typing.cast(typing.Any, ...) |
| 14 |
|
| 15 |
|
| 16 |
class RolesClient: |
| 17 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 18 |
self._raw_client = RawRolesClient(client_wrapper=client_wrapper) |
| 19 |
|
| 20 |
@property |
| 21 |
def with_raw_response(self) -> RawRolesClient: |
| 22 |
""" |
| 23 |
Retrieves a raw implementation of this client that returns raw responses. |
| 24 |
|
| 25 |
Returns |
| 26 |
------- |
| 27 |
RawRolesClient |
| 28 |
""" |
| 29 |
return self._raw_client |
| 30 |
|
| 31 |
def list( |
| 32 |
self, |
| 33 |
id: str, |
| 34 |
*, |
| 35 |
per_page: typing.Optional[int] = 50, |
| 36 |
page: typing.Optional[int] = 0, |
| 37 |
include_totals: typing.Optional[bool] = True, |
| 38 |
request_options: typing.Optional[RequestOptions] = None, |
| 39 |
) -> SyncPager[Role, ListUserRolesOffsetPaginatedResponseContent]: |
| 40 |
""" |
| 41 |
Retrieve detailed list of all user roles currently assigned to a user. |
| 42 |
|
| 43 |
**Note**: This action retrieves all roles assigned to a user in the context of your whole tenant. To retrieve Organization-specific roles, use the following endpoint: [Get user roles assigned to an Organization member](https://auth0.com/docs/api/management/v2/organizations/get-organization-member-roles). |
| 44 |
|
| 45 |
Parameters |
| 46 |
---------- |
| 47 |
id : str |
| 48 |
ID of the user to list roles for. |
| 49 |
|
| 50 |
per_page : typing.Optional[int] |
| 51 |
Number of results per page. |
| 52 |
|
| 53 |
page : typing.Optional[int] |
| 54 |
Page index of the results to return. First page is 0. |
| 55 |
|
| 56 |
include_totals : typing.Optional[bool] |
| 57 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 58 |
|
| 59 |
request_options : typing.Optional[RequestOptions] |
| 60 |
Request-specific configuration. |
| 61 |
|
| 62 |
Returns |
| 63 |
------- |
| 64 |
SyncPager[Role, ListUserRolesOffsetPaginatedResponseContent] |
| 65 |
Roles successfully retrieved. |
| 66 |
|
| 67 |
Examples |
| 68 |
-------- |
| 69 |
from auth0 import Auth0 |
| 70 |
|
| 71 |
client = Auth0( |
| 72 |
token="YOUR_TOKEN", |
| 73 |
) |
| 74 |
response = client.users.roles.list( |
| 75 |
id="id", |
| 76 |
per_page=1, |
| 77 |
page=1, |
| 78 |
include_totals=True, |
| 79 |
) |
| 80 |
for item in response: |
| 81 |
yield item |
| 82 |
# alternatively, you can paginate page-by-page |
| 83 |
for page in response.iter_pages(): |
| 84 |
yield page |
| 85 |
""" |
| 86 |
return self._raw_client.list( |
| 87 |
id, per_page=per_page, page=page, include_totals=include_totals, request_options=request_options |
| 88 |
) |
| 89 |
|
| 90 |
def assign( |
| 91 |
self, id: str, *, roles: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None |
| 92 |
) -> None: |
| 93 |
""" |
| 94 |
Assign one or more existing user roles to a user. For more information, review [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac). |
| 95 |
|
| 96 |
**Note**: New roles cannot be created through this action. Additionally, this action is used to assign roles to a user in the context of your whole tenant. To assign roles in the context of a specific Organization, use the following endpoint: [Assign user roles to an Organization member](https://auth0.com/docs/api/management/v2/organizations/post-organization-member-roles). |
| 97 |
|
| 98 |
Parameters |
| 99 |
---------- |
| 100 |
id : str |
| 101 |
ID of the user to associate roles with. |
| 102 |
|
| 103 |
roles : typing.Sequence[str] |
| 104 |
List of roles IDs to associated with the user. |
| 105 |
|
| 106 |
request_options : typing.Optional[RequestOptions] |
| 107 |
Request-specific configuration. |
| 108 |
|
| 109 |
Returns |
| 110 |
------- |
| 111 |
None |
| 112 |
|
| 113 |
Examples |
| 114 |
-------- |
| 115 |
from auth0 import Auth0 |
| 116 |
|
| 117 |
client = Auth0( |
| 118 |
token="YOUR_TOKEN", |
| 119 |
) |
| 120 |
client.users.roles.assign( |
| 121 |
id="id", |
| 122 |
roles=["roles"], |
| 123 |
) |
| 124 |
""" |
| 125 |
_response = self._raw_client.assign(id, roles=roles, request_options=request_options) |
| 126 |
return _response.data |
| 127 |
|
| 128 |
def delete( |
| 129 |
self, id: str, *, roles: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None |
| 130 |
) -> None: |
| 131 |
""" |
| 132 |
Remove one or more specified user roles assigned to a user. |
| 133 |
|
| 134 |
**Note**: This action removes a role from a user in the context of your whole tenant. If you want to unassign a role from a user in the context of a specific Organization, use the following endpoint: [Delete user roles from an Organization member](https://auth0.com/docs/api/management/v2/organizations/delete-organization-member-roles). |
| 135 |
|
| 136 |
Parameters |
| 137 |
---------- |
| 138 |
id : str |
| 139 |
ID of the user to remove roles from. |
| 140 |
|
| 141 |
roles : typing.Sequence[str] |
| 142 |
List of roles IDs to remove from the user. |
| 143 |
|
| 144 |
request_options : typing.Optional[RequestOptions] |
| 145 |
Request-specific configuration. |
| 146 |
|
| 147 |
Returns |
| 148 |
------- |
| 149 |
None |
| 150 |
|
| 151 |
Examples |
| 152 |
-------- |
| 153 |
from auth0 import Auth0 |
| 154 |
|
| 155 |
client = Auth0( |
| 156 |
token="YOUR_TOKEN", |
| 157 |
) |
| 158 |
client.users.roles.delete( |
| 159 |
id="id", |
| 160 |
roles=["roles"], |
| 161 |
) |
| 162 |
""" |
| 163 |
_response = self._raw_client.delete(id, roles=roles, request_options=request_options) |
| 164 |
return _response.data |
| 165 |
|
| 166 |
|
| 167 |
class AsyncRolesClient: |
| 168 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 169 |
self._raw_client = AsyncRawRolesClient(client_wrapper=client_wrapper) |
| 170 |
|
| 171 |
@property |
| 172 |
def with_raw_response(self) -> AsyncRawRolesClient: |
| 173 |
""" |
| 174 |
Retrieves a raw implementation of this client that returns raw responses. |
| 175 |
|
| 176 |
Returns |
| 177 |
------- |
| 178 |
AsyncRawRolesClient |
| 179 |
""" |
| 180 |
return self._raw_client |
| 181 |
|
| 182 |
async def list( |
| 183 |
self, |
| 184 |
id: str, |
| 185 |
*, |
| 186 |
per_page: typing.Optional[int] = 50, |
| 187 |
page: typing.Optional[int] = 0, |
| 188 |
include_totals: typing.Optional[bool] = True, |
| 189 |
request_options: typing.Optional[RequestOptions] = None, |
| 190 |
) -> AsyncPager[Role, ListUserRolesOffsetPaginatedResponseContent]: |
| 191 |
""" |
| 192 |
Retrieve detailed list of all user roles currently assigned to a user. |
| 193 |
|
| 194 |
**Note**: This action retrieves all roles assigned to a user in the context of your whole tenant. To retrieve Organization-specific roles, use the following endpoint: [Get user roles assigned to an Organization member](https://auth0.com/docs/api/management/v2/organizations/get-organization-member-roles). |
| 195 |
|
| 196 |
Parameters |
| 197 |
---------- |
| 198 |
id : str |
| 199 |
ID of the user to list roles for. |
| 200 |
|
| 201 |
per_page : typing.Optional[int] |
| 202 |
Number of results per page. |
| 203 |
|
| 204 |
page : typing.Optional[int] |
| 205 |
Page index of the results to return. First page is 0. |
| 206 |
|
| 207 |
include_totals : typing.Optional[bool] |
| 208 |
Return results inside an object that contains the total result count (true) or as a direct array of results (false, default). |
| 209 |
|
| 210 |
request_options : typing.Optional[RequestOptions] |
| 211 |
Request-specific configuration. |
| 212 |
|
| 213 |
Returns |
| 214 |
------- |
| 215 |
AsyncPager[Role, ListUserRolesOffsetPaginatedResponseContent] |
| 216 |
Roles successfully retrieved. |
| 217 |
|
| 218 |
Examples |
| 219 |
-------- |
| 220 |
import asyncio |
| 221 |
|
| 222 |
from auth0 import AsyncAuth0 |
| 223 |
|
| 224 |
client = AsyncAuth0( |
| 225 |
token="YOUR_TOKEN", |
| 226 |
) |
| 227 |
|
| 228 |
|
| 229 |
async def main() -> None: |
| 230 |
response = await client.users.roles.list( |
| 231 |
id="id", |
| 232 |
per_page=1, |
| 233 |
page=1, |
| 234 |
include_totals=True, |
| 235 |
) |
| 236 |
async for item in response: |
| 237 |
yield item |
| 238 |
|
| 239 |
# alternatively, you can paginate page-by-page |
| 240 |
async for page in response.iter_pages(): |
| 241 |
yield page |
| 242 |
|
| 243 |
|
| 244 |
asyncio.run(main()) |
| 245 |
""" |
| 246 |
return await self._raw_client.list( |
| 247 |
id, per_page=per_page, page=page, include_totals=include_totals, request_options=request_options |
| 248 |
) |
| 249 |
|
| 250 |
async def assign( |
| 251 |
self, id: str, *, roles: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None |
| 252 |
) -> None: |
| 253 |
""" |
| 254 |
Assign one or more existing user roles to a user. For more information, review [Role-Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac). |
| 255 |
|
| 256 |
**Note**: New roles cannot be created through this action. Additionally, this action is used to assign roles to a user in the context of your whole tenant. To assign roles in the context of a specific Organization, use the following endpoint: [Assign user roles to an Organization member](https://auth0.com/docs/api/management/v2/organizations/post-organization-member-roles). |
| 257 |
|
| 258 |
Parameters |
| 259 |
---------- |
| 260 |
id : str |
| 261 |
ID of the user to associate roles with. |
| 262 |
|
| 263 |
roles : typing.Sequence[str] |
| 264 |
List of roles IDs to associated with the user. |
| 265 |
|
| 266 |
request_options : typing.Optional[RequestOptions] |
| 267 |
Request-specific configuration. |
| 268 |
|
| 269 |
Returns |
| 270 |
------- |
| 271 |
None |
| 272 |
|
| 273 |
Examples |
| 274 |
-------- |
| 275 |
import asyncio |
| 276 |
|
| 277 |
from auth0 import AsyncAuth0 |
| 278 |
|
| 279 |
client = AsyncAuth0( |
| 280 |
token="YOUR_TOKEN", |
| 281 |
) |
| 282 |
|
| 283 |
|
| 284 |
async def main() -> None: |
| 285 |
await client.users.roles.assign( |
| 286 |
id="id", |
| 287 |
roles=["roles"], |
| 288 |
) |
| 289 |
|
| 290 |
|
| 291 |
asyncio.run(main()) |
| 292 |
""" |
| 293 |
_response = await self._raw_client.assign(id, roles=roles, request_options=request_options) |
| 294 |
return _response.data |
| 295 |
|
| 296 |
async def delete( |
| 297 |
self, id: str, *, roles: typing.Sequence[str], request_options: typing.Optional[RequestOptions] = None |
| 298 |
) -> None: |
| 299 |
""" |
| 300 |
Remove one or more specified user roles assigned to a user. |
| 301 |
|
| 302 |
**Note**: This action removes a role from a user in the context of your whole tenant. If you want to unassign a role from a user in the context of a specific Organization, use the following endpoint: [Delete user roles from an Organization member](https://auth0.com/docs/api/management/v2/organizations/delete-organization-member-roles). |
| 303 |
|
| 304 |
Parameters |
| 305 |
---------- |
| 306 |
id : str |
| 307 |
ID of the user to remove roles from. |
| 308 |
|
| 309 |
roles : typing.Sequence[str] |
| 310 |
List of roles IDs to remove from the user. |
| 311 |
|
| 312 |
request_options : typing.Optional[RequestOptions] |
| 313 |
Request-specific configuration. |
| 314 |
|
| 315 |
Returns |
| 316 |
------- |
| 317 |
None |
| 318 |
|
| 319 |
Examples |
| 320 |
-------- |
| 321 |
import asyncio |
| 322 |
|
| 323 |
from auth0 import AsyncAuth0 |
| 324 |
|
| 325 |
client = AsyncAuth0( |
| 326 |
token="YOUR_TOKEN", |
| 327 |
) |
| 328 |
|
| 329 |
|
| 330 |
async def main() -> None: |
| 331 |
await client.users.roles.delete( |
| 332 |
id="id", |
| 333 |
roles=["roles"], |
| 334 |
) |
| 335 |
|
| 336 |
|
| 337 |
asyncio.run(main()) |
| 338 |
""" |
| 339 |
_response = await self._raw_client.delete(id, roles=roles, request_options=request_options) |
| 340 |
return _response.data |