Skip to content

Commit

Permalink
[Communication] - Use Azure.Core.AccessToken instead of custom type (#…
Browse files Browse the repository at this point in the history
…18212)

* [Communication] - Use AccessToken instead of custom type

* Update the snippets

* Update the Changelog and readme
  • Loading branch information
RezaJooyandeh authored Jan 27, 2021
1 parent aac8172 commit 211cab8
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ This client library allows to do following operations:
- Purchase, configure and release phone numbers.

#### You can find samples for each of these functions below.
- Generate user tokens [synchronously][sample_identity] or [asynchronously][sample_identity_async]
- Manage phone numbers [synchronously][sample_admin] or [asynchronously][sample_admin_async]

<!-- LINKS -->
[sample_identity]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/communication/Azure.Communication.Administration/samples/Sample1_CommunicationIdentityClient.md
[sample_identity_async]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/communication/Azure.Communication.Administration/samples/Sample1_CommunicationIdentityClientAsync.md
[sample_admin]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/communication/Azure.Communication.Administration/samples/Sample2_PhoneNumberAdministrationClient.md
[sample_admin_async]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/communication/Azure.Communication.Administration/samples/Sample2_PhoneNumberAdministrationClientAsync.md

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions sdk/communication/Azure.Communication.Chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ For the generation of user access tokens, refer to [User Access Tokens][useracce

### Using statements
```C# Snippet:Azure_Communication_Chat_Tests_E2E_UsingStatements
using Azure.Core;
using Azure.Communication;
using Azure.Communication.Identity;
using Azure.Communication.Chat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net;
using System.Threading.Tasks;
#region Snippet:Azure_Communication_Chat_Tests_E2E_UsingStatements
using Azure.Core;
using Azure.Communication;
using Azure.Communication.Identity;
//@@ using Azure.Communication.Chat;
Expand Down Expand Up @@ -471,7 +472,7 @@ public async Task ReadReceiptGSAsync()
{
Response<CommunicationUserIdentifier> threadMember = communicationIdentityClient.CreateUser();
IEnumerable<CommunicationTokenScope> scopes = new[] { CommunicationTokenScope.Chat };
Response<CommunicationUserToken> tokenResponseThreadMember = communicationIdentityClient.IssueToken(threadMember.Value, scopes);
Response<AccessToken> tokenResponseThreadMember = communicationIdentityClient.IssueToken(threadMember.Value, scopes);

return (threadMember.Value, tokenResponseThreadMember.Value.Token);
}
Expand All @@ -480,7 +481,7 @@ public async Task ReadReceiptGSAsync()
{
Response<CommunicationUserIdentifier> threadMember = await communicationIdentityClient.CreateUserAsync();
IEnumerable<CommunicationTokenScope> scopes = new[] { CommunicationTokenScope.Chat };
Response<CommunicationUserToken> tokenResponseThreadMember = await communicationIdentityClient.IssueTokenAsync(threadMember.Value, scopes);
Response<AccessToken> tokenResponseThreadMember = await communicationIdentityClient.IssueTokenAsync(threadMember.Value, scopes);

return (threadMember.Value, tokenResponseThreadMember.Value.Token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Azure.Communication;
using Azure.Core.TestFramework;
using NUnit.Framework;
using Azure.Core;

namespace Azure.Communication.Chat.Tests.samples
{
Expand All @@ -18,7 +19,7 @@ public async Task CreateGetUpdateDeleteThreadAsync()
{
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClient(TestEnvironment.ConnectionString);
Response<CommunicationUserIdentifier> threadMember = await communicationIdentityClient.CreateUserAsync();
CommunicationUserToken communicationUserToken = await communicationIdentityClient.IssueTokenAsync(threadMember.Value, new[] { CommunicationTokenScope.Chat });
AccessToken communicationUserToken = await communicationIdentityClient.IssueTokenAsync(threadMember.Value, new[] { CommunicationTokenScope.Chat });
string userToken = communicationUserToken.Token;
string endpoint = TestEnvironment.ChatApiUrl();
string threadCreatorId = threadMember.Value.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Azure.Communication;
using Azure.Core.TestFramework;
using NUnit.Framework;
using Azure.Core;

namespace Azure.Communication.Chat.Tests.samples
{
Expand All @@ -18,7 +19,7 @@ public async Task SendGetUpdateDeleteMessagesSendNotificationReadReceiptsAsync()
{
CommunicationIdentityClient communicationIdentityClient = new CommunicationIdentityClient(TestEnvironment.ConnectionString);
Response<CommunicationUserIdentifier> threadMember = await communicationIdentityClient.CreateUserAsync();
CommunicationUserToken communicationUserToken = await communicationIdentityClient.IssueTokenAsync(threadMember.Value, new[] { CommunicationTokenScope.Chat });
AccessToken communicationUserToken = await communicationIdentityClient.IssueTokenAsync(threadMember.Value, new[] { CommunicationTokenScope.Chat });
string userToken = communicationUserToken.Token;
string endpoint = TestEnvironment.ChatApiUrl();
string theadCreatorMemberId = threadMember.Value.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Azure.Communication;
using Azure.Core.TestFramework;
using NUnit.Framework;
using Azure.Core;

namespace Azure.Communication.Chat.Tests.samples
{
Expand All @@ -21,9 +22,9 @@ public async Task GetAddRemoveMembersAsync()
Response<CommunicationUserIdentifier> threadMember2 = await communicationIdentityClient.CreateUserAsync();
Response<CommunicationUserIdentifier> threadMember3 = await communicationIdentityClient.CreateUserAsync();

CommunicationUserToken communicationUserToken1 = await communicationIdentityClient.IssueTokenAsync(threadMember1.Value, new[] { CommunicationTokenScope.Chat });
CommunicationUserToken communicationUserToken2 = await communicationIdentityClient.IssueTokenAsync(threadMember2.Value, new[] { CommunicationTokenScope.Chat });
CommunicationUserToken communicationUserToken3 = await communicationIdentityClient.IssueTokenAsync(threadMember3.Value, new[] { CommunicationTokenScope.Chat });
AccessToken communicationUserToken1 = await communicationIdentityClient.IssueTokenAsync(threadMember1.Value, new[] { CommunicationTokenScope.Chat });
AccessToken communicationUserToken2 = await communicationIdentityClient.IssueTokenAsync(threadMember2.Value, new[] { CommunicationTokenScope.Chat });
AccessToken communicationUserToken3 = await communicationIdentityClient.IssueTokenAsync(threadMember3.Value, new[] { CommunicationTokenScope.Chat });
string userToken = communicationUserToken1.Token;
string endpoint = TestEnvironment.ChatApiUrl();
string theadCreatorMemberId = threadMember1.Value.Id;
Expand Down
3 changes: 3 additions & 0 deletions sdk/communication/Azure.Communication.Identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
- Added CommunicationIdentityClient (originally was part of the Azure.Communication.Administration package).
- Added support to create CommunicationIdentityClient with TokenCredential.
- Added support to create CommunicationIdentityClient with AzureKeyCredential.
- Added ability to create a user and issue token for it at the same time.

### Breaking
- CommunicationTokenScope.Pstn is removed.
- CommunicationIdentityClient.RevokeTokens tokens now revoke all the currently issued tokens instead of revoking tokens issued prior to a given time.
- CommunicationIdentityClient.IssueToken returns an instance of `Azure.Core.AccessToken` instead of `CommunicationUserToken`.

<!-- LINKS -->
[read_me]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/communication/Azure.Communication.Identity/README.md
Expand Down
4 changes: 2 additions & 2 deletions sdk/communication/Azure.Communication.Identity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ CommunicationUserIdentifier user = userResponse.Value;
Console.WriteLine($"User id: {user.Id}");
```

### Issuing or Refreshing a token for an existing identity
### Issuing a token for an existing user

```C# Snippet:CreateCommunicationTokenAsync
Response<CommunicationUserToken> tokenResponse = await client.IssueTokenAsync(user, scopes: new[] { CommunicationTokenScope.Chat });
Response<AccessToken> tokenResponse = await client.IssueTokenAsync(user, scopes: new[] { CommunicationTokenScope.Chat });
string token = tokenResponse.Value.Token;
DateTimeOffset expiresOn = tokenResponse.Value.ExpiresOn;
Console.WriteLine($"Token: {token}");
Expand Down
Loading

0 comments on commit 211cab8

Please sign in to comment.