diff --git a/sdk/communication/Azure.Communication.Identity/api/Azure.Communication.Identity.netstandard2.0.cs b/sdk/communication/Azure.Communication.Identity/api/Azure.Communication.Identity.netstandard2.0.cs index 539cd98a9954..978f2aa5ac76 100644 --- a/sdk/communication/Azure.Communication.Identity/api/Azure.Communication.Identity.netstandard2.0.cs +++ b/sdk/communication/Azure.Communication.Identity/api/Azure.Communication.Identity.netstandard2.0.cs @@ -15,6 +15,8 @@ public CommunicationIdentityClient(System.Uri endpoint, Azure.Core.TokenCredenti public virtual System.Threading.Tasks.Task DeleteUserAsync(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response GetToken(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Collections.Generic.IEnumerable scopes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetTokenAsync(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Collections.Generic.IEnumerable scopes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response GetTurnCredentials(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetTurnCredentialsAsync(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.Response RevokeTokens(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task RevokeTokensAsync(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } @@ -45,3 +47,19 @@ public enum ServiceVersion public override string ToString() { throw null; } } } +namespace Azure.Communication.Identity.Models +{ + public partial class CommunicationTurnCredentialsResponse + { + internal CommunicationTurnCredentialsResponse() { } + public System.DateTimeOffset ExpiresOn { get { throw null; } } + public System.Collections.Generic.IReadOnlyList TurnServers { get { throw null; } } + } + public partial class CommunicationTurnServer + { + internal CommunicationTurnServer() { } + public string Credential { get { throw null; } } + public string Urls { get { throw null; } } + public string Username { get { throw null; } } + } +} diff --git a/sdk/communication/Azure.Communication.Identity/samples/README.md b/sdk/communication/Azure.Communication.Identity/samples/README.md index 74f6f18f5faa..fdbbf7a20bbc 100644 --- a/sdk/communication/Azure.Communication.Identity/samples/README.md +++ b/sdk/communication/Azure.Communication.Identity/samples/README.md @@ -14,14 +14,13 @@ description: Samples for the Azure.Communication.Identity client library Azure Communication Identity is a client library that is used to do operations necessary for identities and tokens. To get started you will need to have an Azure Subscription. Once you have this you can go into the Azure portal and create Azure Communication Services resource. The page will give you necessary information to be able to use the sample codes here such as connections string, shared access key, etc. -This client library allows to do following operations: - - Generate user tokens that allows the holders to access Azure Communication Services. - - Purchase, configure and release phone numbers. +This client library allows for the following operations: + - Generate user tokens that allow the bearers to access Azure Communication Services. + - Generate TURN server credentials that allow the bearers to access a TURN server for media relay. - #### You can find samples for each of these functions below. - - Generate user tokens [synchronously][sample_identity] or [asynchronously][sample_identity_async] + You can find samples for each of these functions below. + - Generate user tokens and TURN credentials [synchronously][sample_identity] or [asynchronously][sample_identity_async] [sample_identity]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/communication/Azure.Communication.Identity/samples/Sample1_CommunicationIdentityClient.md [sample_identity_async]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/communication/Azure.Communication.Identity/samples/Sample1_CommunicationIdentityClientAsync.md -[ diff --git a/sdk/communication/Azure.Communication.Identity/samples/Sample1_CommunicationIdentityClient.md b/sdk/communication/Azure.Communication.Identity/samples/Sample1_CommunicationIdentityClient.md index 607f2cc1a1f5..3332ca9177ec 100644 --- a/sdk/communication/Azure.Communication.Identity/samples/Sample1_CommunicationIdentityClient.md +++ b/sdk/communication/Azure.Communication.Identity/samples/Sample1_CommunicationIdentityClient.md @@ -53,7 +53,7 @@ You will need to store the `identity` that is returned by Azure Communication Se In the example code snippet below, it is assumed that the token is generated for a user on your application. During token generation you should also pass list of scopes to Azure Communication Services, so the token generated by Azure Communication Services is authorized only to do things determined by `scopes`. -Every token generated has an expiry date stamped on it. Once the token is expired, you can renew the token by calling the same method. +Every token generated has an expiry date and time stamped on it. Once the token has expired, you can renew the token by calling the same method. ```C# Snippet:CreateCommunicationToken Response tokenResponse = client.GetToken(user, scopes: new[] { CommunicationTokenScope.Chat }); @@ -63,6 +63,26 @@ Console.WriteLine($"Token: {token}"); Console.WriteLine($"Expires On: {expiresOn}"); ``` +## Generate TURN credentials + +The example code snippet below shows how to generate TURN credentials for an Azure Communication user that was created following the steps above. +A set of TURN credentials are returned for the user. Each TURN credential consists of a URL for a TURN server, its corresponding username and a credential. + +Every set of TURN credentials has an expiry date and time stamped on it. Once the credentials have expired, you can renew the token by calling the same method. + +```C# Snippet:CreateTURNTokenAsync +Response turnTokenResponse = await client.GetTurnCredentialsAsync(user); +DateTimeOffset turnTokenExpiresOn = turnTokenResponse.Value.ExpiresOn; +IReadOnlyList turnServers = turnTokenResponse.Value.TurnServers; +Console.WriteLine($"Expires On: {turnTokenExpiresOn}"); +foreach (CommunicationTurnServer turnServer in turnServers) +{ + Console.WriteLine($"TURN Url: {turnServer.Urls}"); + Console.WriteLine($"TURN Username: {turnServer.Username}"); + Console.WriteLine($"TURN Credential: {turnServer.Credential}"); +} +``` + -Every token generated has an expiry date stamped on it. Once the token is expired, you can renew the token by calling the same method. +Every token generated has an expiry date and time stamped on it. Once the token has expired, you can renew the token by calling the same method. ```C# Snippet:CreateCommunicationTokenAsync Response tokenResponse = await client.GetTokenAsync(user, scopes: new[] { CommunicationTokenScope.Chat }); @@ -65,6 +65,26 @@ Console.WriteLine($"Token: {token}"); Console.WriteLine($"Expires On: {expiresOn}"); ``` +## Generate TURN credentials + +The example code snippet below shows how to generate TURN credentials for an Azure Communication user that was created following the steps above. +A set of TURN credentials are returned for the user. Each TURN credential consists of a URL for a TURN server, its corresponding username and a credential. + +Every set of TURN credentials has an expiry date and time stamped on it. Once the credentials have expired, you can renew the token by calling the same method. + +```C# Snippet:CreateTURNTokenAsync +Response turnTokenResponse = await client.GetTurnCredentialsAsync(user); +DateTimeOffset turnTokenExpiresOn = turnTokenResponse.Value.ExpiresOn; +IReadOnlyList turnServers = turnTokenResponse.Value.TurnServers; +Console.WriteLine($"Expires On: {turnTokenExpiresOn}"); +foreach (CommunicationTurnServer turnServer in turnServers) +{ + Console.WriteLine($"TURN Url: {turnServer.Urls}"); + Console.WriteLine($"TURN Username: {turnServer.Username}"); + Console.WriteLine($"TURN Credential: {turnServer.Credential}"); +} +``` +