Server Version: Identity client: 2020-07-20-preview2
Azure Communication Administration is managing tokens and phone numbers for Azure Communication Services.
Install the Azure Communication Administration client library for .NET with NuGet:
dotnet add package Azure.Communication.Administration --version 1.0.0-beta.1
You need an Azure subscription and a Communication Service resource to use this package.
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);
CommunicationIdentityClient
provides the functionalities to manage user access tokens: creating new ones, renewing and revoking them.
Response<CommunicationUser> userResponse = await client.CreateUserAsync();
CommunicationUser user = userResponse.Value;
Console.WriteLine($"User id: {user.Id}");
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}");
In case a user's tokens are compromised or need to be revoked:
Response revokeResponse = client.RevokeTokens(
user,
issuedBefore: DateTimeOffset.UtcNow.AddDays(-1) /* optional */);
Response deleteResponse = client.DeleteUser(user);
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);
}
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.