public EventManager(AuthPackageReq req, Action <int, AuthPackageResp> loginCallBack, LoginClient c) { _challenge = new AuthChallenge(); _state = LoginAuthState.GetChallenge; _req = req; _client = c; OnLoginCallBack = loginCallBack; }
private async Task ProcessWsAuth(CancellationToken cancellationToken) { var authChallenge = new AuthChallenge() { Seq = 1, Action = "authentication_challenge", AuthData = new AuthChallenge.Data() { Token = authToken } }; await ClientWebSocket.SendAsync <AuthChallenge>(authChallenge, cancellationToken); }
/// <summary> /// Logs into Zenfolio API /// </summary> /// <param name="loginName">User's login name</param> /// <param name="password">User's password</param> /// <returns>True if login was successful, false otherwise.</returns> public bool Login(string loginName, string password) { if (string.IsNullOrEmpty(loginName)) { throw new Exception("Username invalid"); } if (string.IsNullOrEmpty(password)) { throw new Exception("Password invalid"); } try { // Get API challenge AuthChallenge ch = this.GetChallenge(loginName); // Extract and hash password bytes byte[] passwordHash = HashData(ch.PasswordSalt, Encoding.UTF8.GetBytes(password)); // Compute secret proof byte[] proof = HashData(ch.Challenge, passwordHash); // Authenticate _token = this.Authenticate(ch.Challenge, proof); if (_token != null) { _loginName = loginName; return(true); } } catch (Exception ex) { throw ex; // Swallow all exceptions and return false } return(false); }
internal Auth ToAPIAuthentication() { if (sdkAuth == null) { return(apiAuth); } Auth auth = new Auth(); auth.Scheme = new AuthenticationMethodConverter(sdkAuth.Method).ToAPIAuthMethod(); foreach (Challenge challenge in sdkAuth.Challenges) { AuthChallenge authChallenge = new AuthChallenge(); authChallenge.Question = challenge.Question; authChallenge.Answer = challenge.Answer; authChallenge.MaskInput = challenge.MaskOption == Challenge.MaskOptions.MaskInput; auth.AddChallenge(authChallenge); } if (sdkAuth.IdvWorkflow != null) { auth.IdvWorkflow = new IdvWorkflowConverter(sdkAuth.IdvWorkflow).ToAPIIdvWorkflow(); } if (!String.IsNullOrEmpty(sdkAuth.PhoneNumber)) { AuthChallenge challenge = new AuthChallenge(); challenge.Question = sdkAuth.PhoneNumber; auth.AddChallenge(challenge); } return(auth); }