Skip to content

Commit f865619

Browse files
authored
Merge pull request #71 from cabauman/master
Add public API to unlink providers
2 parents 62a59f2 + 777f618 commit f865619

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

src/Firebase.Auth/FirebaseAuthLink.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public async Task<FirebaseAuthLink> LinkToAsync(string email, string password)
4141
}
4242

4343
/// <summary>
44-
/// Links the this user with and account from a third party provider.
44+
/// Links the user with an account from a third party provider.
4545
/// </summary>
4646
/// <param name="authType"> The auth type. </param>
4747
/// <param name="oauthAccessToken"> The access token retrieved from login provider of your choice. </param>
@@ -55,6 +55,20 @@ public async Task<FirebaseAuthLink> LinkToAsync(FirebaseAuthType authType, strin
5555
return this;
5656
}
5757

58+
/// <summary>
59+
/// Unlinks the user from the given <see cref="authType"/> (provider).
60+
/// </summary>
61+
/// <param name="authType"> The auth type. </param>
62+
/// <returns> The <see cref="FirebaseAuthLink"/>. </returns>
63+
public async Task<FirebaseAuthLink> UnlinkFromAsync(FirebaseAuthType authType)
64+
{
65+
var auth = await this.AuthProvider.UnlinkAccountsAsync(this, authType).ConfigureAwait(false);
66+
67+
this.CopyPropertiesLocally(auth.AuthProvider, auth);
68+
69+
return this;
70+
}
71+
5872
public async Task RefreshUserDetails()
5973
{
6074
if (this.AuthProvider != null && !string.IsNullOrEmpty(this.FirebaseToken))

src/Firebase.Auth/FirebaseAuthProvider.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public async Task SendEmailVerificationAsync(FirebaseAuth auth)
229229
}
230230

231231
/// <summary>
232-
/// Links the authenticated user represented by <see cref="auth"/> with an email and password.
232+
/// Links the given <see cref="firebaseToken"/> with an email and password.
233233
/// </summary>
234234
/// <param name="firebaseToken"> The FirebaseToken (idToken) of an authenticated user. </param>
235235
/// <param name="email"> The email. </param>
@@ -255,7 +255,7 @@ public async Task<FirebaseAuthLink> LinkAccountsAsync(FirebaseAuth auth, string
255255
}
256256

257257
/// <summary>
258-
/// Links the authenticated user represented by <see cref="auth"/> with and account from a third party provider.
258+
/// Links the given <see cref="firebaseToken"/> with an account from a third party provider.
259259
/// </summary>
260260
/// <param name="firebaseToken"> The FirebaseToken (idToken) of an authenticated user. </param>
261261
/// <param name="authType"> The auth type. </param>
@@ -270,7 +270,7 @@ public async Task<FirebaseAuthLink> LinkAccountsAsync(string firebaseToken, Fire
270270
}
271271

272272
/// <summary>
273-
/// Links the authenticated user represented by <see cref="auth"/> with and account from a third party provider.
273+
/// Links the authenticated user represented by <see cref="auth"/> with an account from a third party provider.
274274
/// </summary>
275275
/// <param name="auth"> The auth. </param>
276276
/// <param name="authType"> The auth type. </param>
@@ -281,6 +281,40 @@ public async Task<FirebaseAuthLink> LinkAccountsAsync(FirebaseAuth auth, Firebas
281281
return await this.LinkAccountsAsync(auth.FirebaseToken, authType, oauthAccessToken).ConfigureAwait(false);
282282
}
283283

284+
/// <summary>
285+
/// Unlinks the given <see cref="authType"/> from the account associated with <see cref="firebaseToken"/>.
286+
/// </summary>
287+
/// <param name="firebaseToken"> The FirebaseToken (idToken) of an authenticated user. </param>
288+
/// <param name="authType"> The auth type. </param>
289+
/// <returns> The <see cref="FirebaseAuthLink"/>. </returns>
290+
public async Task<FirebaseAuthLink> UnlinkAccountsAsync(string firebaseToken, FirebaseAuthType authType)
291+
{
292+
string providerId = null;
293+
if (authType == FirebaseAuthType.EmailAndPassword)
294+
{
295+
providerId = authType.ToEnumString();
296+
}
297+
else
298+
{
299+
providerId = this.GetProviderId(authType);
300+
}
301+
302+
var content = $"{{\"idToken\":\"{firebaseToken}\",\"deleteProvider\":[\"{providerId}\"]}}";
303+
304+
return await this.ExecuteWithPostContentAsync(GoogleSetAccountUrl, content).ConfigureAwait(false);
305+
}
306+
307+
/// <summary>
308+
/// Unlinks the given <see cref="authType"/> from the authenticated user represented by <see cref="auth"/>.
309+
/// </summary>
310+
/// <param name="auth"> The auth. </param>
311+
/// <param name="authType"> The auth type. </param>
312+
/// <returns> The <see cref="FirebaseAuthLink"/>. </returns>
313+
public async Task<FirebaseAuthLink> UnlinkAccountsAsync(FirebaseAuth auth, FirebaseAuthType authType)
314+
{
315+
return await this.UnlinkAccountsAsync(auth.FirebaseToken, authType).ConfigureAwait(false);
316+
}
317+
284318
/// <summary>
285319
/// Gets a list of accounts linked to given email.
286320
/// </summary>

src/Firebase.Auth/IFirebaseAuthProvider.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ public interface IFirebaseAuthProvider
8989
/// <returns> The <see cref="FirebaseAuthLink"/>. </returns>
9090
Task<FirebaseAuthLink> LinkAccountsAsync(string firebaseToken, FirebaseAuthType authType, string oauthAccessToken);
9191

92+
/// <summary>
93+
/// Unlinks the given <see cref="authType"/> from the account associated with <see cref="firebaseToken"/>.
94+
/// </summary>
95+
/// <param name="firebaseToken"> The FirebaseToken (idToken) of an authenticated user. </param>
96+
/// <param name="authType"> The auth type. </param>
97+
/// <returns> The <see cref="FirebaseAuthLink"/>. </returns>
98+
Task<FirebaseAuthLink> UnlinkAccountsAsync(string firebaseToken, FirebaseAuthType authType);
99+
100+
/// <summary>
101+
/// Unlinks the given <see cref="authType"/> from the authenticated user represented by <see cref="auth"/>.
102+
/// </summary>
103+
/// <param name="auth"> The auth. </param>
104+
/// <param name="authType"> The auth type. </param>
105+
/// <returns> The <see cref="FirebaseAuthLink"/>. </returns>
106+
Task<FirebaseAuthLink> UnlinkAccountsAsync(FirebaseAuth auth, FirebaseAuthType authType);
107+
92108
/// <summary>
93109
/// Gets a list of accounts linked to given email.
94110
/// </summary>

0 commit comments

Comments
 (0)