Skip to content

Commit 4aa3127

Browse files
replaced the internal "JSON-representation-class" with a public one
FirebaseAuth returns now: - DownloadAccountResponse --> ExportedUserRecords - UserRecord --> ExportedUserRecord FirebaseAuth takes now ListUsersOptions
1 parent 89547e7 commit 4aa3127

File tree

9 files changed

+226
-33
lines changed

9 files changed

+226
-33
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright 2019, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
namespace FirebaseAdmin.Auth
16+
{
17+
/// <summary>
18+
/// Contains metadata associated with a Firebase user account.
19+
/// </summary>
20+
public sealed class ExportedUserRecord
21+
{
22+
/// <summary>
23+
/// Gets or sets the user's ID.
24+
/// </summary>
25+
public string UserId { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the user's email address.
29+
/// </summary>
30+
public string Email { get; set; }
31+
32+
/// <summary>
33+
/// Gets or sets the user's phone number.
34+
/// </summary>
35+
public string PhoneNumber { get; set; }
36+
37+
/// <summary>
38+
/// Gets or sets a value indicating whether the user's email address is verified or not.
39+
/// </summary>
40+
public bool EmailVerified { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the user's display name.
44+
/// </summary>
45+
public string DisplayName { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the URL for the user's photo.
49+
/// </summary>
50+
public string PhotoUrl { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets a value indicating whether the user is disabled or not.
54+
/// </summary>
55+
public bool Disabled { get; set; }
56+
57+
/// <summary>
58+
/// Gets or sets the timestamp representing the time that the user account was created.
59+
/// </summary>
60+
public long CreatedAt { get; set; }
61+
62+
/// <summary>
63+
/// Gets or sets the timestamp representing the last time that the user has logged in.
64+
/// </summary>
65+
public long LastLoginAt { get; set; }
66+
67+
/// <summary>
68+
/// Gets or sets the timestamp representing the time that the user account was first valid.
69+
/// </summary>
70+
public long ValidSince { get; set; }
71+
72+
/// <summary>
73+
/// Gets or sets the user's custom claims.
74+
/// </summary>
75+
public string CustomClaims { get; set; }
76+
77+
internal static ExportedUserRecord CreateFrom(GetAccountInfoResponse.User userRecord)
78+
{
79+
return new ExportedUserRecord
80+
{
81+
UserId = userRecord.UserId,
82+
Email = userRecord.Email,
83+
PhoneNumber = userRecord.PhoneNumber,
84+
EmailVerified = userRecord.EmailVerified,
85+
DisplayName = userRecord.DisplayName,
86+
PhotoUrl = userRecord.PhotoUrl,
87+
Disabled = userRecord.Disabled,
88+
CreatedAt = userRecord.CreatedAt,
89+
LastLoginAt = userRecord.LastLoginAt,
90+
ValidSince = userRecord.ValidSince,
91+
CustomClaims = userRecord.CustomClaims,
92+
};
93+
}
94+
}
95+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2019, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System.Collections.Generic;
16+
17+
namespace FirebaseAdmin.Auth
18+
{
19+
/// <summary>
20+
/// Contains a collection of Firebase user accounts.
21+
/// </summary>
22+
public sealed class ExportedUserRecords
23+
{
24+
/// <summary>
25+
/// Gets or sets the next page link.
26+
/// </summary>
27+
public string NextPageToken { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the users.
31+
/// </summary>
32+
public List<ExportedUserRecord> Users { get; set; }
33+
}
34+
}

FirebaseAdmin/FirebaseAdmin/Auth/FirebaseAuth.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,13 @@ public async Task SetCustomUserClaimsAsync(
351351
/// <summary>
352352
/// Gets an async enumerable to page users starting from the specified pageToken. If the pageToken is empty, it starts from the first page.
353353
/// </summary>
354-
/// <param name="pageToken">The page token for the next remote call.</param>
354+
/// <param name="requestOptions">The options for the next remote call.</param>
355355
/// <returns>A <see cref="PagedAsyncEnumerable{DownloadAccountResponse, UserRecord}"/> instance.</returns>
356-
public PagedAsyncEnumerable<DownloadAccountResponse, UserRecord> ListUsersAsync(string pageToken)
356+
public PagedAsyncEnumerable<ExportedUserRecords, ExportedUserRecord> ListUsersAsync(ListUsersOptions requestOptions)
357357
{
358358
var userManager = this.IfNotDeleted(() => this.userManager.Value);
359-
var requestOptions = new UserRecordServiceRequest.UserRecordServiceRequestOptions() { NextPageToken = pageToken };
360359

361-
var restPagedAsyncEnumerable = new RestPagedAsyncEnumerable<UserRecordServiceRequest, DownloadAccountResponse, UserRecord>(
360+
var restPagedAsyncEnumerable = new RestPagedAsyncEnumerable<UserRecordServiceRequest, ExportedUserRecords, ExportedUserRecord>(
362361
() => userManager.CreateUserRecordServiceRequest(requestOptions),
363362
new UserRecordPageManager());
364363

FirebaseAdmin/FirebaseAdmin/Auth/FirebaseUserManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17-
using System.Linq;
1817
using System.Net.Http;
1918
using System.Threading;
2019
using System.Threading.Tasks;
@@ -100,7 +99,7 @@ public async Task<UserRecord> GetUserById(
10099
return new UserRecord(user);
101100
}
102101

103-
public UserRecordServiceRequest CreateUserRecordServiceRequest(UserRecordServiceRequest.UserRecordServiceRequestOptions requestOptions)
102+
public UserRecordServiceRequest CreateUserRecordServiceRequest(ListUsersOptions requestOptions)
104103
{
105104
return new UserRecordServiceRequest(this.baseUrl, this.httpClient, requestOptions);
106105
}

FirebaseAdmin/FirebaseAdmin/Auth/Internal/DownloadAccountResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace FirebaseAdmin.Auth
2020
/// <summary>
2121
/// JSON data binding for downloadAccountResponse messages sent by Google identity toolkit service.
2222
/// </summary>
23-
public class DownloadAccountResponse
23+
internal class DownloadAccountResponse
2424
{
2525
/// <summary>
2626
/// Gets or sets the next page link.

FirebaseAdmin/FirebaseAdmin/Auth/Internal/GetAccountInfoResponse.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace FirebaseAdmin.Auth
66
/// <summary>
77
/// JSON data binding for GetAccountInfoResponse messages sent by Google identity toolkit service.
88
/// </summary>
9-
public sealed class GetAccountInfoResponse
9+
internal sealed class GetAccountInfoResponse
1010
{
1111
/// <summary>
1212
/// Gets or sets a string representing what kind of account is represented by this object.
@@ -23,7 +23,7 @@ public sealed class GetAccountInfoResponse
2323
/// <summary>
2424
/// JSON data binding for user records.
2525
/// </summary>
26-
public sealed class User
26+
internal sealed class User
2727
{
2828
/// <summary>
2929
/// Gets or sets the user's ID.
@@ -101,7 +101,7 @@ public sealed class User
101101
/// <summary>
102102
/// JSON data binding for provider data.
103103
/// </summary>
104-
public sealed class Provider
104+
internal sealed class Provider
105105
{
106106
/// <summary>
107107
/// Gets or sets the user's ID.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2019, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using Google.Api.Gax;
16+
17+
namespace FirebaseAdmin.Auth
18+
{
19+
/// <summary>
20+
/// Options for <c>ListUsersOptions</c> operations.
21+
/// </summary>
22+
public sealed class ListUsersOptions
23+
{
24+
/// <summary>
25+
/// Gets or sets the number of results to return per page. (This modifies the per-request page size;
26+
/// it does not affect the total number of results returned.)
27+
/// </summary>
28+
public int? PageSize { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the page-token.
32+
/// If set, this token is used to indicate a continued list operation.
33+
/// The value should be taken from the <c>NextPageToken</c> property of either
34+
/// a <see cref="Page{TResource}"/> or a raw response from <see cref="PagedEnumerable{TResponse, TResource}.AsRawResponses"/>.
35+
/// </summary>
36+
public string PageToken { get; set; }
37+
}
38+
}

FirebaseAdmin/FirebaseAdmin/Auth/UserRecordPageManager.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
// Copyright 2019, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
using System.Collections.Generic;
216
using Google.Api.Gax.Rest;
317

418
namespace FirebaseAdmin.Auth
519
{
6-
internal class UserRecordPageManager : IPageManager<UserRecordServiceRequest, DownloadAccountResponse, UserRecord>
20+
internal class UserRecordPageManager : IPageManager<UserRecordServiceRequest, ExportedUserRecords, ExportedUserRecord>
721
{
822
public void SetPageSize(UserRecordServiceRequest request, int pageSize)
923
{
@@ -15,20 +29,17 @@ public void SetPageToken(UserRecordServiceRequest request, string pageToken)
1529
request.SetPageToken(pageToken);
1630
}
1731

18-
public IEnumerable<UserRecord> GetResources(DownloadAccountResponse response)
32+
public IEnumerable<ExportedUserRecord> GetResources(ExportedUserRecords response)
1933
{
2034
if (response?.Users == null)
2135
{
22-
yield break;
36+
return new ExportedUserRecord[0];
2337
}
2438

25-
foreach (var user in response.Users)
26-
{
27-
yield return new UserRecord(user);
28-
}
39+
return response.Users;
2940
}
3041

31-
public string GetNextPageToken(DownloadAccountResponse response)
42+
public string GetNextPageToken(ExportedUserRecords response)
3243
{
3344
return string.IsNullOrEmpty(response.NextPageToken) ? null : response.NextPageToken;
3445
}

FirebaseAdmin/FirebaseAdmin/Auth/UserRecordServiceRequest.cs

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2019, Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
using System;
216
using System.Collections.Generic;
317
using System.IO;
@@ -12,22 +26,22 @@
1226

1327
namespace FirebaseAdmin.Auth
1428
{
15-
internal class UserRecordServiceRequest : IClientServiceRequest<DownloadAccountResponse>
29+
internal class UserRecordServiceRequest : IClientServiceRequest<ExportedUserRecords>
1630
{
1731
private readonly string baseUrl;
1832
private readonly HttpClient httpClient;
19-
private readonly UserRecordServiceRequestOptions requestOptions;
33+
private readonly ListUsersOptions requestOptions;
2034

21-
internal UserRecordServiceRequest(string baseUrl, HttpClient httpClient, UserRecordServiceRequestOptions requestOptions)
35+
internal UserRecordServiceRequest(string baseUrl, HttpClient httpClient, ListUsersOptions requestOptions)
2236
{
2337
this.baseUrl = baseUrl;
2438
this.httpClient = httpClient;
2539
this.requestOptions = requestOptions;
2640
this.RequestParameters = new Dictionary<string, IParameter>();
2741

2842
// this is the default page-size if no other value is set.
29-
this.SetPageSize(FirebaseUserManager.MaxListUsersResults);
30-
this.SetPageToken(requestOptions.NextPageToken);
43+
this.SetPageSize(requestOptions.PageSize ?? FirebaseUserManager.MaxListUsersResults);
44+
this.SetPageToken(requestOptions.PageToken);
3145
}
3246

3347
public string MethodName => "ListUsers";
@@ -48,7 +62,7 @@ public void SetPageSize(int pageSize)
4862
public void SetPageToken(string pageToken)
4963
{
5064
this.AddOrUpdate("nextPageToken", pageToken);
51-
this.requestOptions.NextPageToken = pageToken;
65+
this.requestOptions.PageToken = pageToken;
5266
}
5367

5468
public HttpRequestMessage CreateRequest(bool? overrideGZipEnabled = null)
@@ -80,21 +94,29 @@ public Stream ExecuteAsStream()
8094
return this.ExecuteAsStreamAsync().Result;
8195
}
8296

83-
public Task<DownloadAccountResponse> ExecuteAsync()
97+
public Task<ExportedUserRecords> ExecuteAsync()
8498
{
8599
return this.ExecuteAsync(default);
86100
}
87101

88-
public Task<DownloadAccountResponse> ExecuteAsync(CancellationToken cancellationToken)
102+
public async Task<ExportedUserRecords> ExecuteAsync(CancellationToken cancellationToken)
89103
{
90-
return this.SendAndDeserializeAsync<DownloadAccountResponse>(this.CreateRequest(), cancellationToken);
104+
var downloadAccountResponse = await this.SendAndDeserializeAsync<DownloadAccountResponse>(this.CreateRequest(), cancellationToken);
105+
return ConvertToExportedUserRecords(downloadAccountResponse);
91106
}
92107

93-
public DownloadAccountResponse Execute()
108+
public ExportedUserRecords Execute()
94109
{
95110
return this.ExecuteAsync().Result;
96111
}
97112

113+
private static ExportedUserRecords ConvertToExportedUserRecords(DownloadAccountResponse downloadAccountResponse)
114+
{
115+
var userRecords = new List<ExportedUserRecord>();
116+
downloadAccountResponse.Users?.ForEach(u => userRecords.Add(ExportedUserRecord.CreateFrom(u)));
117+
return new ExportedUserRecords { NextPageToken = downloadAccountResponse.NextPageToken, Users = userRecords };
118+
}
119+
98120
private async Task<TResult> SendAndDeserializeAsync<TResult>(HttpRequestMessage request, CancellationToken cancellationToken)
99121
{
100122
var response = await this.SendAsync(request, cancellationToken).ConfigureAwait(false);
@@ -155,10 +177,5 @@ private void AddOrUpdate(string paramName, string value)
155177
this.RequestParameters[paramName] = parameter;
156178
}
157179
}
158-
159-
internal class UserRecordServiceRequestOptions
160-
{
161-
public string NextPageToken { get; set; }
162-
}
163180
}
164181
}

0 commit comments

Comments
 (0)