Azure Communication Administration client library for .NET
Server Version: Identity client: 2020-07-20-preview2
Azure Communication Administration is managing tokens and phone numbers for Azure Communication Services.
Getting started
Install the package
Install the Azure Communication Administration client library for .NET with NuGet:
dotnet add package Azure.Communication.Administration --version 1.0.0-beta.1
Prerequisites
You need an Azure subscription and a Communication Service resource to use this package.
Authenticate the client
Administration clients can be authenticated using connection string acquired from an Azure Communication Resources in the Azure Portal.
// Get a connection string to our Azure Communication resource.
var connectionString = "<connection_string>";
var client = new CommunicationIdentityClient(connectionString);
Key concepts
CommunicationIdentityClient
provides the functionalities to manage user access tokens: creating new ones, renewing and revoking them.
Examples
Create a new identity
Response<CommunicationUser> userResponse = await client.CreateUserAsync();
CommunicationUser user = userResponse.Value;
Console.WriteLine($"User id: {user.Id}");
Issuing or Refreshing a token for an existing identity
Response<CommunicationUserToken> tokenResponse = await client.IssueTokenAsync(user, scopes: new[] { CommunicationTokenScope.Chat });
string token = tokenResponse.Value.Token;
DateTimeOffset expiresOn = tokenResponse.Value.ExpiresOn;
Console.WriteLine($"Token: {token}");
Console.WriteLine($"Expires On: {expiresOn}");
Revoking a user's tokens
In case a user's tokens are compromised or need to be revoked:
Response revokeResponse = client.RevokeTokens(
user,
issuedBefore: DateTimeOffset.UtcNow.AddDays(-1) /* optional */);
Deleting a user
Response deleteResponse = client.DeleteUser(user);
Troubleshooting
All User token service operations will throw a [RequestFailedException][RequestFailedException] on failure.
// Get a connection string to our Azure Communication resource.
var connectionString = "<connection_string>";
var client = new CommunicationIdentityClient(connectionString);
try
{
Response<CommunicationUser> response = await client.CreateUserAsync();
}
catch (RequestFailedException ex)
{
Console.WriteLine(ex.Message);
}
Next steps
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.