async public Task <Tuple <UserInfo, string> > SignInAsync(string userId, string password, bool isCredentialStore) { Tuple <LogonResult, string> result = null; try { var userInfo = new UserInfo { Name = userId, UserId = userId }; result = await _identityService.LogonAsync(userId, password); if (result.Item1 == null) { return(new Tuple <UserInfo, string>(null, result.Item2)); } UserInfo previousUser = _signedInUser; _signedInUser = result.Item1.UserInfo; _sessionStateService.SessionState[SignedInUserKey] = _signedInUser; _userId = userId; _password = password; _sessionStateService.SessionState[UserIdKey] = userId; _sessionStateService.SessionState[PasswordKey] = password; if (isCredentialStore) { _credentialStore.SaveCredentials(PasswordVaultResourceName, userId, password); } if (previousUser == null) { RaiseUserChanged(_signedInUser, previousUser); } else if (_signedInUser != null && _signedInUser.UserId != previousUser.UserId) { RaiseUserChanged(_signedInUser, previousUser); } return(new Tuple <UserInfo, string>(_signedInUser, "")); } catch (Exception) { return(new Tuple <UserInfo, string>(null, result.Item2)); } }
public async Task <bool> SignInUserAsync(string userName, string password, bool useCredentialStore) { try { var result = await _identityService.LogOnAsync(userName, password); UserInfo previousUser = _signedInUser; _signedInUser = result.UserInfo; // Save SignedInUser in the StateService _sessionStateService.SessionState[SignedInUserKey] = _signedInUser; // Save username and password in state service _userName = userName; _password = password; _sessionStateService.SessionState[UserNameKey] = userName; _sessionStateService.SessionState[PasswordKey] = password; if (useCredentialStore) { // Save credentials in the CredentialStore _credentialStore.SaveCredentials(PasswordVaultResourceName, userName, password); // Documentation on managing application data is at http://go.microsoft.com/fwlink/?LinkID=288818&clcid=0x409 } if (previousUser == null) { // Raise use changed event if user logged in RaiseUserChanged(_signedInUser, previousUser); } else if (_signedInUser != null && _signedInUser.UserName != previousUser.UserName) { // Raise use changed event if user changed RaiseUserChanged(_signedInUser, previousUser); } return(true); } catch (Exception) { } return(false); }
public async Task <LogOnResult> SignInUserAsync(string userName, string password, bool useCredentialStore) { var result = await _developerService.SignInAsync(userName, password); if (!result.SignedIn) { return(result); } var previousUser = SignedInUser; SignedInUser = result.UserInfo; // Save SignedInUser in the StateService _sessionStateService.SessionState[SignedInUserKey] = SignedInUser; // Save username and password in state service _userName = userName; _password = password; _sessionStateService.SessionState[UserNameKey] = userName; _sessionStateService.SessionState[PasswordKey] = password; if (useCredentialStore) { // Save credentials in the CredentialStore _credentialStore.SaveCredentials(PasswordVaultResourceName, userName, password); } if (previousUser == null) { // Raise use changed event if user logged in RaiseUserChanged(SignedInUser, previousUser); } else if (SignedInUser != null && SignedInUser.PrimaryEmail != previousUser.PrimaryEmail) { // Raise use changed event if user changed RaiseUserChanged(SignedInUser, previousUser); } return(result); }