Skip to content

Commit 7dadde7

Browse files
[Communication] - Identity - Rename CommunicationIdentityClient.CreateUserWithToken* and Change the return type (Azure#19177)
* Rename CommunicationIdentityClient.CreateUserWithToken* and Change the return type * Rename CommunicationUserIdentifierAndTokenResult to CommunicationUserIdentifierAndToken
1 parent f0b5262 commit 7dadde7

10 files changed

+136
-81
lines changed

sdk/communication/Azure.Communication.Identity/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.0.0-beta.5 (Unreleased)
44
### Breaking
55
- CommunicationIdentityClient.IssueToken and CommunicationIdentityClient.IssueTokenAsync are renamed to GetToken and GetTokenAsync, respectively.
6+
- CommunicationIdentityClient.CreateUserWithToken and CommunicationIdentityClient.CreateUserWithTokenAsync are renamed to CreateUserAndToken and CreateUserAndTokenAsync, respectively. Their return value is also changed from Tuple<CommunicationUserIdentifier, string> to CommunicationUserIdentifierAndToken.
67

78
## 1.0.0-beta.4 (2021-02-09)
89

sdk/communication/Azure.Communication.Identity/api/Azure.Communication.Identity.netstandard2.0.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public CommunicationIdentityClient(string connectionString, Azure.Communication.
88
public CommunicationIdentityClient(System.Uri endpoint, Azure.AzureKeyCredential keyCredential, Azure.Communication.Identity.CommunicationIdentityClientOptions options = null) { }
99
public CommunicationIdentityClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCredential, Azure.Communication.Identity.CommunicationIdentityClientOptions options = null) { }
1010
public virtual Azure.Response<Azure.Communication.CommunicationUserIdentifier> CreateUser(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
11+
public virtual Azure.Response<Azure.Communication.Identity.CommunicationUserIdentifierAndToken> CreateUserAndToken(System.Collections.Generic.IEnumerable<Azure.Communication.Identity.CommunicationTokenScope> scopes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
12+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Identity.CommunicationUserIdentifierAndToken>> CreateUserAndTokenAsync(System.Collections.Generic.IEnumerable<Azure.Communication.Identity.CommunicationTokenScope> scopes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1113
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.CommunicationUserIdentifier>> CreateUserAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
12-
public virtual Azure.Response<(Azure.Communication.CommunicationUserIdentifier user, Azure.Core.AccessToken token)> CreateUserWithToken(System.Collections.Generic.IEnumerable<Azure.Communication.Identity.CommunicationTokenScope> scopes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
13-
public virtual System.Threading.Tasks.Task<Azure.Response<(Azure.Communication.CommunicationUserIdentifier user, Azure.Core.AccessToken token)>> CreateUserWithTokenAsync(System.Collections.Generic.IEnumerable<Azure.Communication.Identity.CommunicationTokenScope> scopes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1414
public virtual Azure.Response DeleteUser(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1515
public virtual System.Threading.Tasks.Task<Azure.Response> DeleteUserAsync(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
1616
public virtual Azure.Response<Azure.Core.AccessToken> GetToken(Azure.Communication.CommunicationUserIdentifier communicationUser, System.Collections.Generic.IEnumerable<Azure.Communication.Identity.CommunicationTokenScope> scopes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
@@ -44,4 +44,19 @@ public enum ServiceVersion
4444
public static bool operator !=(Azure.Communication.Identity.CommunicationTokenScope left, Azure.Communication.Identity.CommunicationTokenScope right) { throw null; }
4545
public override string ToString() { throw null; }
4646
}
47+
public partial class CommunicationUserIdentifierAndToken
48+
{
49+
internal CommunicationUserIdentifierAndToken() { }
50+
public Azure.Core.AccessToken AccessToken { get { throw null; } }
51+
public Azure.Communication.CommunicationUserIdentifier User { get { throw null; } }
52+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
53+
public void Deconstruct(out Azure.Communication.CommunicationUserIdentifier user, out Azure.Core.AccessToken accessToken) { throw null; }
54+
}
55+
}
56+
namespace Azure.Communication.Identity.Models
57+
{
58+
public static partial class CommunicationIdentityModelFactory
59+
{
60+
public static Azure.Communication.Identity.CommunicationUserIdentifierAndToken CommunicationUserIdentifierAndToken(Azure.Communication.CommunicationUserIdentifier user, Azure.Core.AccessToken accessToken) { throw null; }
61+
}
4762
}

sdk/communication/Azure.Communication.Identity/src/CommunicationIdentityClient.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public virtual Response<CommunicationUserIdentifier> CreateUser(CancellationToke
100100
scope.Start();
101101
try
102102
{
103-
Response<CommunicationIdentityAccessTokenResult> response = RestClient.Create(Array.Empty<CommunicationTokenScope>(), cancellationToken);
103+
Response<CommunicationUserIdentifierAndToken> response = RestClient.Create(Array.Empty<CommunicationTokenScope>(), cancellationToken);
104104
var id = response.Value.Identity.Id;
105105
return Response.FromValue(new CommunicationUserIdentifier(id), response.GetRawResponse());
106106
}
@@ -119,7 +119,7 @@ public virtual async Task<Response<CommunicationUserIdentifier>> CreateUserAsync
119119
scope.Start();
120120
try
121121
{
122-
Response<CommunicationIdentityAccessTokenResult> response = await RestClient.CreateAsync(Array.Empty<CommunicationTokenScope>(), cancellationToken).ConfigureAwait(false);
122+
Response<CommunicationUserIdentifierAndToken> response = await RestClient.CreateAsync(Array.Empty<CommunicationTokenScope>(), cancellationToken).ConfigureAwait(false);
123123
var id = response.Value.Identity.Id;
124124
return Response.FromValue(new CommunicationUserIdentifier(id), response.GetRawResponse());
125125
}
@@ -133,17 +133,13 @@ public virtual async Task<Response<CommunicationUserIdentifier>> CreateUserAsync
133133
/// <summary>Creates a new <see cref="CommunicationUserIdentifier"/>.</summary>
134134
/// <param name="scopes">The scopes that the token should have.</param>
135135
/// <param name="cancellationToken">The cancellation token to use.</param>
136-
public virtual Response<(CommunicationUserIdentifier user, AccessToken token)>
137-
CreateUserWithToken(IEnumerable<CommunicationTokenScope> scopes, CancellationToken cancellationToken = default)
136+
public virtual Response<CommunicationUserIdentifierAndToken> CreateUserAndToken(IEnumerable<CommunicationTokenScope> scopes, CancellationToken cancellationToken = default)
138137
{
139-
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CommunicationIdentityClient)}.{nameof(CreateUserWithToken)}");
138+
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CommunicationIdentityClient)}.{nameof(CreateUserAndToken)}");
140139
scope.Start();
141140
try
142141
{
143-
Response<CommunicationIdentityAccessTokenResult> response = RestClient.Create(scopes, cancellationToken);
144-
var id = response.Value.Identity.Id;
145-
CommunicationIdentityAccessToken rawToken = response.Value.AccessToken;
146-
return Response.FromValue((new CommunicationUserIdentifier(id), new AccessToken(rawToken.Token, rawToken.ExpiresOn)), response.GetRawResponse());
142+
return RestClient.Create(scopes, cancellationToken);
147143
}
148144
catch (Exception ex)
149145
{
@@ -155,17 +151,13 @@ public virtual async Task<Response<CommunicationUserIdentifier>> CreateUserAsync
155151
/// <summary>Asynchronously creates a new <see cref="CommunicationUserIdentifier"/>.</summary>
156152
/// <param name="scopes">The scopes that the token should have.</param>
157153
/// <param name="cancellationToken">The cancellation token to use.</param>
158-
public virtual async Task<Response<(CommunicationUserIdentifier user, AccessToken token)>>
159-
CreateUserWithTokenAsync(IEnumerable<CommunicationTokenScope> scopes, CancellationToken cancellationToken = default)
154+
public virtual async Task<Response<CommunicationUserIdentifierAndToken>> CreateUserAndTokenAsync(IEnumerable<CommunicationTokenScope> scopes, CancellationToken cancellationToken = default)
160155
{
161-
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CommunicationIdentityClient)}.{nameof(CreateUserWithToken)}");
156+
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CommunicationIdentityClient)}.{nameof(CreateUserAndToken)}");
162157
scope.Start();
163158
try
164159
{
165-
Response<CommunicationIdentityAccessTokenResult> response = await RestClient.CreateAsync(scopes, cancellationToken).ConfigureAwait(false);
166-
var id = response.Value.Identity.Id;
167-
CommunicationIdentityAccessToken rawToken = response.Value.AccessToken;
168-
return Response.FromValue((new CommunicationUserIdentifier(id), new AccessToken(rawToken.Token, rawToken.ExpiresOn)), response.GetRawResponse());
160+
return await RestClient.CreateAsync(scopes, cancellationToken).ConfigureAwait(false);
169161
}
170162
catch (Exception ex)
171163
{

sdk/communication/Azure.Communication.Identity/src/Generated/CommunicationIdentityRestClient.cs

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.Identity/src/Generated/Models/CommunicationIdentityAccessTokenResult.cs

Lines changed: 0 additions & 43 deletions
This file was deleted.

sdk/communication/Azure.Communication.Identity/src/Generated/Models/CommunicationIdentityAccessTokenResult.Serialization.cs renamed to sdk/communication/Azure.Communication.Identity/src/Generated/Models/CommunicationUserIdentifierAndToken.Serialization.cs

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.Identity/src/Generated/Models/CommunicationUserIdentifierAndToken.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Azure.Core;
5+
6+
namespace Azure.Communication.Identity.Models
7+
{
8+
/// <summary>
9+
/// Model factory that enables mocking for the Identity library.
10+
/// </summary>
11+
public static class CommunicationIdentityModelFactory
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="CommunicationUserIdentifierAndToken"/> class.
15+
/// </summary>
16+
/// <param name="user"> The user stored in the instance. </param>
17+
/// <param name="accessToken"> The access token stored in the instance. </param>
18+
/// <returns>A new <see cref="CommunicationUserIdentifierAndToken"/> instance for mocking.</returns>
19+
public static CommunicationUserIdentifierAndToken CommunicationUserIdentifierAndToken(CommunicationUserIdentifier user, AccessToken accessToken)
20+
=> new CommunicationUserIdentifierAndToken(new CommunicationIdentity(user.Id), new CommunicationIdentityAccessToken(accessToken.Token, accessToken.ExpiresOn));
21+
}
22+
}

sdk/communication/Azure.Communication.Identity/src/Models/CommunicationUserAccessTokenResult.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)