| 1 |
|
| 2 |
|
| 3 |
import typing |
| 4 |
|
| 5 |
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper |
| 6 |
from ...core.request_options import RequestOptions |
| 7 |
from ...types.delete_user_identity_response_content import DeleteUserIdentityResponseContent |
| 8 |
from ...types.user_id import UserId |
| 9 |
from ...types.user_identity import UserIdentity |
| 10 |
from ...types.user_identity_provider_enum import UserIdentityProviderEnum |
| 11 |
from .raw_client import AsyncRawIdentitiesClient, RawIdentitiesClient |
| 12 |
|
| 13 |
|
| 14 |
OMIT = typing.cast(typing.Any, ...) |
| 15 |
|
| 16 |
|
| 17 |
class IdentitiesClient: |
| 18 |
def __init__(self, *, client_wrapper: SyncClientWrapper): |
| 19 |
self._raw_client = RawIdentitiesClient(client_wrapper=client_wrapper) |
| 20 |
|
| 21 |
@property |
| 22 |
def with_raw_response(self) -> RawIdentitiesClient: |
| 23 |
""" |
| 24 |
Retrieves a raw implementation of this client that returns raw responses. |
| 25 |
|
| 26 |
Returns |
| 27 |
------- |
| 28 |
RawIdentitiesClient |
| 29 |
""" |
| 30 |
return self._raw_client |
| 31 |
|
| 32 |
def link( |
| 33 |
self, |
| 34 |
id: str, |
| 35 |
*, |
| 36 |
provider: typing.Optional[UserIdentityProviderEnum] = OMIT, |
| 37 |
connection_id: typing.Optional[str] = OMIT, |
| 38 |
user_id: typing.Optional[UserId] = OMIT, |
| 39 |
link_with: typing.Optional[str] = OMIT, |
| 40 |
request_options: typing.Optional[RequestOptions] = None, |
| 41 |
) -> typing.List[UserIdentity]: |
| 42 |
""" |
| 43 |
Link two user accounts together forming a primary and secondary relationship. On successful linking, the endpoint returns the new array of the primary account identities. |
| 44 |
|
| 45 |
Note: There are two ways of invoking the endpoint: |
| 46 |
|
| 47 |
- With the authenticated primary account's JWT in the Authorization header, which has the `update:current_user_identities` scope: |
| 48 |
|
| 49 |
```http |
| 50 |
POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities |
| 51 |
Authorization: "Bearer PRIMARY_ACCOUNT_JWT" |
| 52 |
{ |
| 53 |
"link_with": "SECONDARY_ACCOUNT_JWT" |
| 54 |
} |
| 55 |
``` |
| 56 |
|
| 57 |
In this case, only the `link_with` param is required in the body, which also contains the JWT obtained upon the secondary account's authentication. |
| 58 |
|
| 59 |
- With a token generated by the API V2 containing the `update:users` scope: |
| 60 |
|
| 61 |
```http |
| 62 |
POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities |
| 63 |
Authorization: "Bearer YOUR_API_V2_TOKEN" |
| 64 |
{ |
| 65 |
"provider": "SECONDARY_ACCOUNT_PROVIDER", |
| 66 |
"connection_id": "SECONDARY_ACCOUNT_CONNECTION_ID(OPTIONAL)", |
| 67 |
"user_id": "SECONDARY_ACCOUNT_USER_ID" |
| 68 |
} |
| 69 |
``` |
| 70 |
|
| 71 |
In this case you need to send `provider` and `user_id` in the body. Optionally you can also send the `connection_id` param which is suitable for identifying a particular database connection for the 'auth0' provider. |
| 72 |
|
| 73 |
Parameters |
| 74 |
---------- |
| 75 |
id : str |
| 76 |
ID of the primary user account to link a second user account to. |
| 77 |
|
| 78 |
provider : typing.Optional[UserIdentityProviderEnum] |
| 79 |
Identity provider of the secondary user account being linked. |
| 80 |
|
| 81 |
connection_id : typing.Optional[str] |
| 82 |
connection_id of the secondary user account being linked when more than one `auth0` database provider exists. |
| 83 |
|
| 84 |
user_id : typing.Optional[UserId] |
| 85 |
user_id of the secondary user account being linked. |
| 86 |
|
| 87 |
link_with : typing.Optional[str] |
| 88 |
JWT for the secondary account being linked. If sending this parameter, `provider`, `user_id`, and `connection_id` must not be sent. |
| 89 |
|
| 90 |
request_options : typing.Optional[RequestOptions] |
| 91 |
Request-specific configuration. |
| 92 |
|
| 93 |
Returns |
| 94 |
------- |
| 95 |
typing.List[UserIdentity] |
| 96 |
Identity successfully added. |
| 97 |
|
| 98 |
Examples |
| 99 |
-------- |
| 100 |
from auth0 import Auth0 |
| 101 |
|
| 102 |
client = Auth0( |
| 103 |
token="YOUR_TOKEN", |
| 104 |
) |
| 105 |
client.users.identities.link( |
| 106 |
id="id", |
| 107 |
) |
| 108 |
""" |
| 109 |
_response = self._raw_client.link( |
| 110 |
id, |
| 111 |
provider=provider, |
| 112 |
connection_id=connection_id, |
| 113 |
user_id=user_id, |
| 114 |
link_with=link_with, |
| 115 |
request_options=request_options, |
| 116 |
) |
| 117 |
return _response.data |
| 118 |
|
| 119 |
def delete( |
| 120 |
self, |
| 121 |
id: str, |
| 122 |
provider: UserIdentityProviderEnum, |
| 123 |
user_id: str, |
| 124 |
*, |
| 125 |
request_options: typing.Optional[RequestOptions] = None, |
| 126 |
) -> DeleteUserIdentityResponseContent: |
| 127 |
""" |
| 128 |
Unlink a specific secondary account from a target user. This action requires the ID of both the target user and the secondary account. |
| 129 |
|
| 130 |
Unlinking the secondary account removes it from the identities array of the target user and creates a new standalone profile for the secondary account. To learn more, review [Unlink User Accounts](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/unlink-user-accounts). |
| 131 |
|
| 132 |
Parameters |
| 133 |
---------- |
| 134 |
id : str |
| 135 |
ID of the primary user account. |
| 136 |
|
| 137 |
provider : UserIdentityProviderEnum |
| 138 |
Identity provider name of the secondary linked account (e.g. `google-oauth2`). |
| 139 |
|
| 140 |
user_id : str |
| 141 |
ID of the secondary linked account (e.g. `123456789081523216417` part after the `|` in `google-oauth2|123456789081523216417`). |
| 142 |
|
| 143 |
request_options : typing.Optional[RequestOptions] |
| 144 |
Request-specific configuration. |
| 145 |
|
| 146 |
Returns |
| 147 |
------- |
| 148 |
DeleteUserIdentityResponseContent |
| 149 |
User identity successfully unlinked. |
| 150 |
|
| 151 |
Examples |
| 152 |
-------- |
| 153 |
from auth0 import Auth0 |
| 154 |
|
| 155 |
client = Auth0( |
| 156 |
token="YOUR_TOKEN", |
| 157 |
) |
| 158 |
client.users.identities.delete( |
| 159 |
id="id", |
| 160 |
provider="ad", |
| 161 |
user_id="user_id", |
| 162 |
) |
| 163 |
""" |
| 164 |
_response = self._raw_client.delete(id, provider, user_id, request_options=request_options) |
| 165 |
return _response.data |
| 166 |
|
| 167 |
|
| 168 |
class AsyncIdentitiesClient: |
| 169 |
def __init__(self, *, client_wrapper: AsyncClientWrapper): |
| 170 |
self._raw_client = AsyncRawIdentitiesClient(client_wrapper=client_wrapper) |
| 171 |
|
| 172 |
@property |
| 173 |
def with_raw_response(self) -> AsyncRawIdentitiesClient: |
| 174 |
""" |
| 175 |
Retrieves a raw implementation of this client that returns raw responses. |
| 176 |
|
| 177 |
Returns |
| 178 |
------- |
| 179 |
AsyncRawIdentitiesClient |
| 180 |
""" |
| 181 |
return self._raw_client |
| 182 |
|
| 183 |
async def link( |
| 184 |
self, |
| 185 |
id: str, |
| 186 |
*, |
| 187 |
provider: typing.Optional[UserIdentityProviderEnum] = OMIT, |
| 188 |
connection_id: typing.Optional[str] = OMIT, |
| 189 |
user_id: typing.Optional[UserId] = OMIT, |
| 190 |
link_with: typing.Optional[str] = OMIT, |
| 191 |
request_options: typing.Optional[RequestOptions] = None, |
| 192 |
) -> typing.List[UserIdentity]: |
| 193 |
""" |
| 194 |
Link two user accounts together forming a primary and secondary relationship. On successful linking, the endpoint returns the new array of the primary account identities. |
| 195 |
|
| 196 |
Note: There are two ways of invoking the endpoint: |
| 197 |
|
| 198 |
- With the authenticated primary account's JWT in the Authorization header, which has the `update:current_user_identities` scope: |
| 199 |
|
| 200 |
```http |
| 201 |
POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities |
| 202 |
Authorization: "Bearer PRIMARY_ACCOUNT_JWT" |
| 203 |
{ |
| 204 |
"link_with": "SECONDARY_ACCOUNT_JWT" |
| 205 |
} |
| 206 |
``` |
| 207 |
|
| 208 |
In this case, only the `link_with` param is required in the body, which also contains the JWT obtained upon the secondary account's authentication. |
| 209 |
|
| 210 |
- With a token generated by the API V2 containing the `update:users` scope: |
| 211 |
|
| 212 |
```http |
| 213 |
POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities |
| 214 |
Authorization: "Bearer YOUR_API_V2_TOKEN" |
| 215 |
{ |
| 216 |
"provider": "SECONDARY_ACCOUNT_PROVIDER", |
| 217 |
"connection_id": "SECONDARY_ACCOUNT_CONNECTION_ID(OPTIONAL)", |
| 218 |
"user_id": "SECONDARY_ACCOUNT_USER_ID" |
| 219 |
} |
| 220 |
``` |
| 221 |
|
| 222 |
In this case you need to send `provider` and `user_id` in the body. Optionally you can also send the `connection_id` param which is suitable for identifying a particular database connection for the 'auth0' provider. |
| 223 |
|
| 224 |
Parameters |
| 225 |
---------- |
| 226 |
id : str |
| 227 |
ID of the primary user account to link a second user account to. |
| 228 |
|
| 229 |
provider : typing.Optional[UserIdentityProviderEnum] |
| 230 |
Identity provider of the secondary user account being linked. |
| 231 |
|
| 232 |
connection_id : typing.Optional[str] |
| 233 |
connection_id of the secondary user account being linked when more than one `auth0` database provider exists. |
| 234 |
|
| 235 |
user_id : typing.Optional[UserId] |
| 236 |
user_id of the secondary user account being linked. |
| 237 |
|
| 238 |
link_with : typing.Optional[str] |
| 239 |
JWT for the secondary account being linked. If sending this parameter, `provider`, `user_id`, and `connection_id` must not be sent. |
| 240 |
|
| 241 |
request_options : typing.Optional[RequestOptions] |
| 242 |
Request-specific configuration. |
| 243 |
|
| 244 |
Returns |
| 245 |
------- |
| 246 |
typing.List[UserIdentity] |
| 247 |
Identity successfully added. |
| 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.users.identities.link( |
| 262 |
id="id", |
| 263 |
) |
| 264 |
|
| 265 |
|
| 266 |
asyncio.run(main()) |
| 267 |
""" |
| 268 |
_response = await self._raw_client.link( |
| 269 |
id, |
| 270 |
provider=provider, |
| 271 |
connection_id=connection_id, |
| 272 |
user_id=user_id, |
| 273 |
link_with=link_with, |
| 274 |
request_options=request_options, |
| 275 |
) |
| 276 |
return _response.data |
| 277 |
|
| 278 |
async def delete( |
| 279 |
self, |
| 280 |
id: str, |
| 281 |
provider: UserIdentityProviderEnum, |
| 282 |
user_id: str, |
| 283 |
*, |
| 284 |
request_options: typing.Optional[RequestOptions] = None, |
| 285 |
) -> DeleteUserIdentityResponseContent: |
| 286 |
""" |
| 287 |
Unlink a specific secondary account from a target user. This action requires the ID of both the target user and the secondary account. |
| 288 |
|
| 289 |
Unlinking the secondary account removes it from the identities array of the target user and creates a new standalone profile for the secondary account. To learn more, review [Unlink User Accounts](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/unlink-user-accounts). |
| 290 |
|
| 291 |
Parameters |
| 292 |
---------- |
| 293 |
id : str |
| 294 |
ID of the primary user account. |
| 295 |
|
| 296 |
provider : UserIdentityProviderEnum |
| 297 |
Identity provider name of the secondary linked account (e.g. `google-oauth2`). |
| 298 |
|
| 299 |
user_id : str |
| 300 |
ID of the secondary linked account (e.g. `123456789081523216417` part after the `|` in `google-oauth2|123456789081523216417`). |
| 301 |
|
| 302 |
request_options : typing.Optional[RequestOptions] |
| 303 |
Request-specific configuration. |
| 304 |
|
| 305 |
Returns |
| 306 |
------- |
| 307 |
DeleteUserIdentityResponseContent |
| 308 |
User identity successfully unlinked. |
| 309 |
|
| 310 |
Examples |
| 311 |
-------- |
| 312 |
import asyncio |
| 313 |
|
| 314 |
from auth0 import AsyncAuth0 |
| 315 |
|
| 316 |
client = AsyncAuth0( |
| 317 |
token="YOUR_TOKEN", |
| 318 |
) |
| 319 |
|
| 320 |
|
| 321 |
async def main() -> None: |
| 322 |
await client.users.identities.delete( |
| 323 |
id="id", |
| 324 |
provider="ad", |
| 325 |
user_id="user_id", |
| 326 |
) |
| 327 |
|
| 328 |
|
| 329 |
asyncio.run(main()) |
| 330 |
""" |
| 331 |
_response = await self._raw_client.delete(id, provider, user_id, request_options=request_options) |
| 332 |
return _response.data |