-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Communication identity api redesign #16420
Changes from all commits
7238b6c
f06edc1
95dad5f
42e7bfe
727b73c
41e6d57
bc00046
2023e51
94752a2
2c3bddf
6e619e3
996e35d
7fabad5
bff5406
b4e62f7
745848a
3f12d66
366fe36
96c1376
17af7c0
725d8ab
ec749be
6827ba5
e6dded8
935635a
1373bf5
d2eec01
a74c808
b4b3565
2b13610
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,19 +36,58 @@ endpoint = os.getenv('AZURE_COMMUNICATION_SERVICE_ENDPOINT') | |
|
||
# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have | ||
# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables. | ||
identity_client_managed_identity = CommunicationIdentityClient.(endpoint, DefaultAzureCredential()) | ||
identity_client_managed_identity = CommunicationIdentityClient(endpoint, DefaultAzureCredential()) | ||
|
||
#You can also authenticate using your connection string | ||
identity_client = CommunicationIdentityClient.from_connection_string(connection_str) | ||
|
||
``` | ||
|
||
# Examples | ||
## Examples | ||
The following section provides several code snippets covering some of the most common Azure Communication Services tasks, including: | ||
|
||
[Create/delete Azure Communication Service identities][identitysamples] | ||
### Creating a new user | ||
|
||
[Create/revoke scoped user access tokens][identitysamples] | ||
Use the `create_user` method to create a new user. | ||
```python | ||
user = identity_client.create_user() | ||
print("User created with id:" + user.identifier) | ||
``` | ||
|
||
Alternatively, use the `create_user_with_token` method to create a new user and issue a token for it.\ | ||
For this option, a list of `CommunicationTokenScope` must be defined (see "Issuing an access token" for more information) | ||
|
||
```python | ||
user, tokenresponse = identity_client.create_user_with_token(scopes=[CommunicationTokenScope.CHAT]) | ||
print("User id:" + user.identifier) | ||
print("Token issued with value: " + tokenresponse.token) | ||
``` | ||
|
||
### Issuing or Refreshing an access token for a user | ||
|
||
Use the `issue_token` method to issue or refresh a scoped access token for the user. \ | ||
Pass in the user object as a parameter, and a list of `CommunicationTokenScope`. Scope options are: | ||
- `CHAT` (Chat) | ||
- `VOIP` (VoIP) | ||
|
||
```python | ||
tokenresponse = identity_client.issue_token(user, scopes=[CommunicationTokenScope.CHAT]) | ||
print("Token issued with value: " + tokenresponse.token) | ||
``` | ||
|
||
### Revoking a user's access tokens | ||
|
||
Use `revoke_tokens` to revoke all access tokens for a user. Pass in the user object as a parameter | ||
```python | ||
identity_client.revoke_tokens(user) | ||
``` | ||
|
||
### Deleting a user | ||
|
||
Use the `delete_user` method to delete a user. Pass in the user object as a parameter | ||
```python | ||
identity_client.delete_user(user) | ||
``` | ||
|
||
# Troubleshooting | ||
The Azure Communication Service Identity client will raise exceptions defined in [Azure Core][azure_core]. | ||
|
@@ -73,5 +112,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope | |
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. | ||
|
||
<!-- LINKS --> | ||
[identitysamples]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/communication/azure-communication-identity/samples/identity_samples.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we remove this sample? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This link was to just the sync sample. We instead have a place where we link to both the sync/async samples (under "next steps"). The place this link was being used was also just a link, and I've replaced it with fully fleshed out samples instead. |
||
[azure_core]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Remove \ after the .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, i'm doing this to force a newline here. I can still remove it if you think we shouldn't