Skip to content

Commit 27688ad

Browse files
committed
Converted IUserInfo to use properties instead of functions.
1 parent fcad198 commit 27688ad

File tree

5 files changed

+115
-70
lines changed

5 files changed

+115
-70
lines changed

FirebaseAdmin/FirebaseAdmin/Auth/FirebaseAuth.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ public async Task<FirebaseToken> VerifyIdTokenAsync(
267267
/// Gets a <see cref="UserRecord"/> object containig information about the user who's
268268
/// user ID was specified in <paramref name="uid"/>.
269269
/// </summary>
270-
/// <param name="uid">The user ID for the user who's data is to be retrieved..</param>
270+
/// <param name="uid">The user ID for the user who's data is to be retrieved.</param>
271271
/// <returns>A task that completes with a <see cref="UserRecord"/> representing
272272
/// a user with the specified user ID.</returns>
273273
/// <exception cref="ArgumentException">If user ID argument is null or empty.</exception>
274274
/// <exception cref="FirebaseException">If a user cannot be found with the specified user ID.</exception>
275275
public async Task<UserRecord> GetUserAsync(string uid)
276276
{
277-
return await this.userManager.Value.GetUserById(uid);
277+
return await this.GetUserAsync(uid, default(CancellationToken));
278278
}
279279

280280
/// <summary>
@@ -291,7 +291,9 @@ public async Task<UserRecord> GetUserAsync(string uid)
291291
public async Task<UserRecord> GetUserAsync(
292292
string uid, CancellationToken cancellationToken)
293293
{
294-
return await this.userManager.Value.GetUserById(uid, cancellationToken);
294+
var userManager = this.IfNotDeleted(() => this.userManager.Value);
295+
296+
return await userManager.GetUserById(uid, cancellationToken);
295297
}
296298

297299
/// <summary>

FirebaseAdmin/FirebaseAdmin/Auth/IUserInfo.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,58 @@ namespace FirebaseAdmin.Auth
1111
public interface IUserInfo
1212
{
1313
/// <summary>
14-
/// Returns the user's unique ID assigned by the identity provider.
14+
/// Gets the user's unique ID assigned by the identity provider.
1515
/// </summary>
1616
/// <returns>a user ID string.</returns>
17-
string GetUid();
17+
string Uid
18+
{
19+
get;
20+
}
1821

1922
/// <summary>
20-
/// Returns the user's display name, if available.
23+
/// Gets the user's display name, if available.
2124
/// </summary>
2225
/// <returns>a display name string or null.</returns>
23-
string GetDisplayName();
26+
string DisplayName
27+
{
28+
get;
29+
}
2430

2531
/// <summary>
26-
/// Returns the user's email address, if available.
32+
/// Gets the user's email address, if available.
2733
/// </summary>
2834
/// <returns>an email address string or null.</returns>
29-
string GetEmail();
35+
string Email
36+
{
37+
get;
38+
}
3039

3140
/// <summary>
32-
/// Returns the user's phone number, if available.
41+
/// Gets the user's phone number, if available.
3342
/// </summary>
3443
/// <returns>a phone number string or null.</returns>
35-
string GetPhoneNumber();
44+
string PhoneNumber
45+
{
46+
get;
47+
}
3648

3749
/// <summary>
38-
/// Returns the user's photo URL, if available.
50+
/// Gets the user's photo URL, if available.
3951
/// </summary>
4052
/// <returns>a URL string or null.</returns>
41-
string GetPhotoUrl();
53+
string PhotoUrl
54+
{
55+
get;
56+
}
4257

4358
/// <summary>
44-
/// Returns the ID of the identity provider. This can be a short domain name (e.g. google.com) or
59+
/// Gets the ID of the identity provider. This can be a short domain name (e.g. google.com) or
4560
/// the identifier of an OpenID identity provider.
4661
/// </summary>
4762
/// <returns>an ID string that uniquely identifies the identity provider.</returns>
48-
string GetProviderId();
63+
string ProviderId
64+
{
65+
get;
66+
}
4967
}
5068
}

FirebaseAdmin/FirebaseAdmin/Auth/ProviderUserInfo.cs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,58 @@ internal ProviderUserInfo(GetAccountInfoResponse.Provider provider)
3232
}
3333

3434
/// <summary>
35-
/// Returns the user's unique ID assigned by the identity provider.
35+
/// Gets the user's unique ID assigned by the identity provider.
3636
/// </summary>
3737
/// <returns>a user ID string.</returns>
38-
public string GetUid() => this.uid;
38+
public string Uid
39+
{
40+
get => this.uid;
41+
}
3942

4043
/// <summary>
41-
/// Returns the user's display name, if available.
44+
/// Gets the user's display name, if available.
4245
/// </summary>
4346
/// <returns>a display name string or null.</returns>
44-
public string GetDisplayName() => this.displayName;
47+
public string DisplayName
48+
{
49+
get => this.displayName;
50+
}
4551

4652
/// <summary>
47-
/// Returns the user's email address, if available.
53+
/// Gets the user's email address, if available.
4854
/// </summary>
4955
/// <returns>an email address string or null.</returns>
50-
public string GetEmail() => this.email;
56+
public string Email
57+
{
58+
get => this.email;
59+
}
5160

5261
/// <summary>
5362
/// Gets the user's phone number.
5463
/// </summary>
5564
/// <returns>a phone number string or null.</returns>
56-
public string GetPhoneNumber() => this.phoneNumber;
65+
public string PhoneNumber
66+
{
67+
get => this.phoneNumber;
68+
}
5769

5870
/// <summary>
59-
/// Returns the user's photo URL, if available.
71+
/// Gets the user's photo URL, if available.
6072
/// </summary>
6173
/// <returns>a URL string or null.</returns>
62-
public string GetPhotoUrl() => this.photoUrl;
74+
public string PhotoUrl
75+
{
76+
get => this.photoUrl;
77+
}
6378

6479
/// <summary>
65-
/// Returns the ID of the identity provider. This can be a short domain name (e.g. google.com) or
80+
/// Gets the ID of the identity provider. This can be a short domain name (e.g. google.com) or
6681
/// the identifier of an OpenID identity provider.
6782
/// </summary>
6883
/// <returns>an ID string that uniquely identifies the identity provider.</returns>
69-
public string GetProviderId() => this.providerId;
84+
public string ProviderId
85+
{
86+
get => this.providerId;
87+
}
7088
}
7189
}

FirebaseAdmin/FirebaseAdmin/Auth/UserMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public sealed class UserMetadata
1515
/// </summary>
1616
/// <param name="creationTimestamp">A timestamp representing the date and time that the user account was created.</param>
1717
/// <param name="lastSignInTimestamp">A timestamp representing the date and time that the user account was last signed-on to.</param>
18-
public UserMetadata(long creationTimestamp, long lastSignInTimestamp)
18+
internal UserMetadata(long creationTimestamp, long lastSignInTimestamp)
1919
{
2020
this.CreationTimestamp = creationTimestamp;
2121
this.LastSignInTimestamp = lastSignInTimestamp;

FirebaseAdmin/FirebaseAdmin/Auth/UserRecord.cs

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,52 @@ private set
111111
}
112112
}
113113

114+
/// <summary>
115+
/// Gets the user's display name, if available.
116+
/// </summary>
117+
/// <returns>a display name string or null.</returns>
118+
public string DisplayName
119+
{
120+
get => this.displayName;
121+
}
122+
123+
/// <summary>
124+
/// Gets the user's email address, if available.
125+
/// </summary>
126+
/// <returns>an email address string or null.</returns>
127+
public string Email
128+
{
129+
get => this.email;
130+
}
131+
132+
/// <summary>
133+
/// Gets the user's phone number.
134+
/// </summary>
135+
/// <returns>a phone number string or null.</returns>
136+
public string PhoneNumber
137+
{
138+
get => this.phoneNumber;
139+
}
140+
141+
/// <summary>
142+
/// Gets the user's photo URL, if available.
143+
/// </summary>
144+
/// <returns>a URL string or null.</returns>
145+
public string PhotoUrl
146+
{
147+
get => this.photoUrl;
148+
}
149+
150+
/// <summary>
151+
/// Gets the ID of the identity provider. This can be a short domain name (e.g. google.com) or
152+
/// the identifier of an OpenID identity provider.
153+
/// </summary>
154+
/// <returns>an ID string that uniquely identifies the identity provider.</returns>
155+
public string ProviderId
156+
{
157+
get => UserRecord.PROVIDERID;
158+
}
159+
114160
/// <summary>
115161
/// Gets a value indicating whether the user's email address is verified or not.
116162
/// </summary>
@@ -124,7 +170,7 @@ private set
124170
/// <summary>
125171
/// Gets a list of provider data for this user.
126172
/// </summary>
127-
public List<ProviderUserInfo> Providers => this.providers;
173+
public IEnumerable<IUserInfo> Providers => this.providers;
128174

129175
/// <summary>
130176
/// Gets a timestamp representing the date and time that this token will become active.
@@ -170,43 +216,6 @@ public static void CheckUid(string uid)
170216
}
171217
}
172218

173-
/// <summary>
174-
/// Returns the user's unique ID assigned by the identity provider.
175-
/// </summary>
176-
/// <returns>a user ID string.</returns>
177-
public string GetUid() => this.uid;
178-
179-
/// <summary>
180-
/// Returns the user's display name, if available.
181-
/// </summary>
182-
/// <returns>a display name string or null.</returns>
183-
public string GetDisplayName() => this.displayName;
184-
185-
/// <summary>
186-
/// Returns the user's email address, if available.
187-
/// </summary>
188-
/// <returns>an email address string or null.</returns>
189-
public string GetEmail() => this.email;
190-
191-
/// <summary>
192-
/// Gets the user's phone number.
193-
/// </summary>
194-
/// <returns>a phone number string or null.</returns>
195-
public string GetPhoneNumber() => this.phoneNumber;
196-
197-
/// <summary>
198-
/// Returns the user's photo URL, if available.
199-
/// </summary>
200-
/// <returns>a URL string or null.</returns>
201-
public string GetPhotoUrl() => this.photoUrl;
202-
203-
/// <summary>
204-
/// Returns the ID of the identity provider. This can be a short domain name (e.g. google.com) or
205-
/// the identifier of an OpenID identity provider.
206-
/// </summary>
207-
/// <returns>an ID string that uniquely identifies the identity provider.</returns>
208-
public string GetProviderId() => UserRecord.PROVIDERID;
209-
210219
/// <summary>
211220
/// Checks if the given set of custom claims are valid.
212221
/// </summary>
@@ -246,17 +255,15 @@ private static string SerializeClaims(IReadOnlyDictionary<string, object> claims
246255
return NewtonsoftJsonSerializer.Instance.Serialize(claims);
247256
}
248257

249-
private static ReadOnlyDictionary<string, object> ParseCustomClaims(string customClaims)
258+
private static IReadOnlyDictionary<string, object> ParseCustomClaims(string customClaims)
250259
{
251260
if (string.IsNullOrEmpty(customClaims))
252261
{
253-
return new ReadOnlyDictionary<string, object>(new Dictionary<string, object>());
262+
return new Dictionary<string, object>();
254263
}
255264
else
256265
{
257-
var parsed = NewtonsoftJsonSerializer.Instance.Deserialize<Dictionary<string, object>>(customClaims);
258-
259-
return new ReadOnlyDictionary<string, object>(parsed);
266+
return NewtonsoftJsonSerializer.Instance.Deserialize<Dictionary<string, object>>(customClaims);
260267
}
261268
}
262269
}

0 commit comments

Comments
 (0)