public async Task <LoginResult> LoginByAuthStatus(BitwardenAuthStatus authStatus, string email, string password) { try { switch (authStatus.Status) { case BitwardenStatus.Logout: //Need email and password return(await FullLogin(email, password)); case BitwardenStatus.Locked: //Need only password return(await LoginLocked(authStatus, email, password)); case BitwardenStatus.Unlocked: //Need only password return(await LoginUnlocked(authStatus, email, password)); default: throw new ArgumentException($"The status {authStatus.Status} does not exist"); } } catch (Exception ex) { return(LoginResult.CreateFailed(ex.Message)); } }
public static async Task <LoginResult> Login(string requestUserHostAddress, LoginContext loginContext) { try { var sessionToken = await Database.CreateGuestSfsSession(loginContext, requestUserHostAddress); return(LoginResult.CreateSuccess(new { userLoginId = loginContext.GenerateAppScopedLoginId(), sessionToken = sessionToken })); } catch (Exception e) { return(LoginResult.CreateFailed("Oops! Please try signing in again.")); } }
/// <summary> /// Logs the user in with the email and the password /// </summary> /// <param name="email">The email of the bitwarden account</param> /// <param name="password">The password of the bitwarden account</param> /// <returns>The result of the login</returns> public override async Task <LoginResult> Login(string email, string password) { var result = await authService.Login(email, password); if (result.Output == INVALID_LOGIN) { return(LoginResult.CreateFailed(INVALID_LOGIN)); } if (result.Output.Contains(ALREADY_LOGGED_IN)) { return(LoginResult.CreateFailed(result.Output)); } //Login correct return(LoginResult.CreateSucess(email)); }
public static async Task <LoginResult> Login(string accessToken, string ipAddress, LoginContext loginContext) { try { var userLoginId = loginContext.GenerateAppScopedLoginId(); EnsureAccessTokenNotEmpty(accessToken); var tokenDebugInfo = await Facebook.GetFacebookAccessTokenDebugInfo(accessToken); if (!tokenDebugInfo.IsValid() || tokenDebugInfo.user_id != loginContext.UserId) { throw new Exception("Invalid Access Token. " + tokenDebugInfo.GetErrorMessage()); } var sessionToken = await Database.CreateSfsSession(loginContext, ipAddress, accessToken); string tokenToReturn = accessToken; // not doing this for now. let the user renew his 2 hr token //if (tokenDebugInfo.IsTokenExpiringInLessThanOneDay()) //{ // try // { // tokenToReturn = await Facebook.ExchangeTokenForLongLivedToken(accessToken); // await Database.UpdateUserAccessToken(userLoginId, tokenToReturn); // } // catch (Exception e) // { // // do nothing let go as exchanging token or saving it is not important to stop user login flow. it can be done // // at a later login. // } //} return(LoginResult.CreateSuccess(new { newAccessToken = tokenToReturn == accessToken ? null : tokenToReturn, userLoginId = loginContext.GenerateAppScopedLoginId(), sessionToken = sessionToken })); } catch (Exception e) { return(LoginResult.CreateFailed("Oops! Please try signing in again.")); } }
public async Task <LoginResult> Login(LoginModel model) { var user = await _userManager.FindByNameAsync(model.EmployeeId); if (user is null) { return(LoginResult.CreateFailed()); } var isPasswordCorrect = await _userManager.CheckPasswordAsync(user, model.Password); if (!isPasswordCorrect) { return(LoginResult.CreateFailed()); } var principal = await _signInManager.CreateUserPrincipalAsync(user); var token = CreateToken(principal); return(LoginResult.CreateSucceeded(token)); }
public override async Task <LoginResult> Unlock(string password) { var result = await authService.Unlock(password); if (!result.Output.Contains("--session")) { return(LoginResult.CreateFailed(result.Output)); } string session = LoginResultConverter.GetSessionKey(result.Output); Environment.SetEnvironmentVariable("BW_SESSION", session); var authResult = await GetAuthStatus(); if (authResult.Status == BitwardenStatus.Unlocked) { return(LoginResult.CreateSucess(authResult.UserEmail)); } else { return(LoginResult.CreateFailed("The vault could not be unlocked")); } }