@@ -25,6 +25,9 @@ public class FirebaseAuthProvider : IDisposable, IFirebaseAuthProvider
25
25
private const string GoogleSetAccountUrl = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/setAccountInfo?key={0}" ;
26
26
private const string GoogleCreateAuthUrl = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/createAuthUri?key={0}" ;
27
27
28
+ private const string ProfileDeleteDisplayName = "DISPLAY_NAME" ;
29
+ private const string ProfileDeletePhotoUrl = "PHOTO_URL" ;
30
+
28
31
private readonly FirebaseConfig authConfig ;
29
32
private readonly HttpClient client ;
30
33
@@ -160,6 +163,39 @@ public async Task<FirebaseAuthLink> CreateUserWithEmailAndPasswordAsync(string e
160
163
return signup ;
161
164
}
162
165
166
+ /// <summary>
167
+ /// Updates profile (displayName and photoUrl) of user tied to given user token.
168
+ /// </summary>
169
+ /// <param name="displayName"> The new display name. </param>
170
+ /// <param name="photoUrl"> The new photo URL. </param>
171
+ /// <returns> The <see cref="FirebaseAuthLink"/>. </returns>
172
+ public async Task < FirebaseAuthLink > UpdateProfileAsync ( string firebaseToken , string displayName , string photoUrl )
173
+ {
174
+ StringBuilder sb = new StringBuilder ( $ "{{\" idToken\" :\" { firebaseToken } \" ") ;
175
+ if ( ! string . IsNullOrWhiteSpace ( displayName ) && ! string . IsNullOrWhiteSpace ( photoUrl ) )
176
+ {
177
+ sb . Append ( $ ",\" displayName\" :\" { displayName } \" ,\" photoUrl\" :\" { photoUrl } \" ") ;
178
+ }
179
+ else if ( ! string . IsNullOrWhiteSpace ( displayName ) )
180
+ {
181
+ sb . Append ( $ ",\" displayName\" :\" { displayName } \" ") ;
182
+ sb . Append ( $ ",\" deleteAttribute\" :[\" { ProfileDeletePhotoUrl } \" ]") ;
183
+ }
184
+ else if ( ! string . IsNullOrWhiteSpace ( photoUrl ) )
185
+ {
186
+ sb . Append ( $ ",\" photoUrl\" :\" { photoUrl } \" ") ;
187
+ sb . Append ( $ ",\" deleteAttribute\" :[\" { ProfileDeleteDisplayName } \" ]") ;
188
+ }
189
+ else
190
+ {
191
+ sb . Append ( $ ",\" deleteAttribute\" :[\" { ProfileDeleteDisplayName } \" ,\" { ProfileDeletePhotoUrl } \" ]") ;
192
+ }
193
+
194
+ sb . Append ( $ ",\" returnSecureToken\" :true}}") ;
195
+
196
+ return await this . ExecuteWithPostContentAsync ( GoogleSetAccountUrl , sb . ToString ( ) ) . ConfigureAwait ( false ) ;
197
+ }
198
+
163
199
/// <summary>
164
200
/// Deletes the user with a recent Firebase Token.
165
201
/// </summary>
0 commit comments