Keeper |
Class | Description | |
---|---|---|
![]() | Auth | Represents Keeper authentication. (async) |
Interface | Description | |
---|---|---|
![]() | IAuthSsoUI | Defines the methods required completing SSO Login. Optional. |
![]() | IAuthUI | Defines the user interface methods required for authentication with Keeper. |
using System.Linq; using System.Threading; using System.Threading.Tasks; using KeeperSecurity.Authentication; using KeeperSecurity.Authentication.Async; using KeeperSecurity.Configuration; class AuthUi : IAuthUI { public Task<bool> WaitForDeviceApproval(IDeviceApprovalChannelInfo[] channels, CancellationToken token) { // find email device approval channel. var emailChannel = channels .Cast<IDeviceApprovalPushInfo>() .FirstOrDefault(x => x.Channel == DeviceApprovalChannel.Email); if (emailChannel != null) { // invoke send email action. _ = Task.Run(async () => { await emailChannel.InvokeDeviceApprovalPushAction(); }); } return new TaskCompletionSource<bool>().Task; } public async Task<bool> WaitForTwoFactorCode(ITwoFactorChannelInfo[] channels, CancellationToken token) { // find 2FA code channel. var codeChannel = channels .Cast<ITwoFactorAppCodeInfo>() .FirstOrDefault(); if (codeChannel != null) { Console.WriteLine("Enter 2FA code: "); var code = Console.ReadLine(); await codeChannel.InvokeTwoFactorCodeAction("code"); return true; } return false; } public async Task<bool> WaitForUserPassword(IPasswordInfo info, CancellationToken token) { Console.WriteLine($"Enter password for {info.Username}: "); var password = Console.ReadLine(); await info.InvokePasswordActionDelegate(password); return true; } } internal static class Program { private static async Task Main() { var auth = new Auth(new AuthUi(), new JsonConfigurationStorage()); await auth.Login("username@company.com"); } }