Skip to content

Commit

Permalink
Implemented Get Mfa Recovery Codes
Browse files Browse the repository at this point in the history
  • Loading branch information
pingu2k4 committed Aug 10, 2024
1 parent a008c8b commit bd3abe4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/PinguApps.Appwrite.Client/Clients/AccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,19 @@ public async Task<AppwriteResult<MfaRecoveryCodes>> CreateMfaRecoveryCodes()
return e.GetExceptionResponse<MfaRecoveryCodes>();
}
}

/// <inheritdoc/>
public async Task<AppwriteResult<MfaRecoveryCodes>> GetMfaRecoveryCodes()
{
try
{
var result = await _accountApi.GetMfaRecoveryCodes(GetCurrentSessionOrThrow());

return result.GetApiResponse();
}
catch (Exception e)
{
return e.GetExceptionResponse<MfaRecoveryCodes>();
}
}
}
7 changes: 7 additions & 0 deletions src/PinguApps.Appwrite.Client/Clients/IAccountClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,11 @@ public interface IAccountClient
/// </summary>
/// <returns>The Mfa Recovery Codes</returns>
Task<AppwriteResult<MfaRecoveryCodes>> CreateMfaRecoveryCodes();

/// <summary>
/// Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using <see cref="CreateMfaRecoveryCodes"/> method. An OTP challenge is required to read recovery codes
/// <para><see href="https://appwrite.io/docs/references/1.5.x/client-rest/account#getMfaRecoveryCodes">Appwrite Docs</see></para>
/// </summary>
/// <returns>The Mfa Recovery Codes</returns>
Task<AppwriteResult<MfaRecoveryCodes>> GetMfaRecoveryCodes();
}
3 changes: 3 additions & 0 deletions src/PinguApps.Appwrite.Client/Internals/IAccountApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ internal interface IAccountApi : IBaseApi

[Post("/account/mfa/recovery-codes")]
Task<IApiResponse<MfaRecoveryCodes>> CreateMfaRecoveryCodes([Header("x-appwrite-session")] string session);

[Get("/account/mfa/recovery-codes")]
Task<IApiResponse<MfaRecoveryCodes>> GetMfaRecoveryCodes([Header("x-appwrite-session")] string session);
}
2 changes: 1 addition & 1 deletion src/PinguApps.Appwrite.Playground/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task Run(string[] args)
{
_client.SetSession(_session);

var response = await _client.Account.CreateMfaRecoveryCodes();
var response = await _client.Account.GetMfaRecoveryCodes();

Console.WriteLine(response.Result.Match(
account => account.ToString(),
Expand Down

0 comments on commit bd3abe4

Please sign in to comment.