public AuthResult TryToken(string userName, byte[] token) { BindUser(userName); Send(BinaryMessage.Make(CMD_USETOKEN).Bytes(token).Complete()); var reply = GetReply(); if (reply.Type != 0) { return(AuthResult.Fail()); } var cookie = reply.GetData(); return(AuthResult.Success(userName, cookie)); }
public AuthResult TryPassword(string userName, string password) { BindUser(userName); byte[] phash = Digest(password); Send(BinaryMessage.Make(CMD_PASSWD).Bytes(phash).Complete()); var reply = GetReply(); if (reply.Type != 0) { return(AuthResult.Fail()); } var cookie = reply.GetData(); return(AuthResult.Success(userName, cookie)); }
public AuthResult TryToken(string userName, byte[] token) { var reply = Call(CmdTryToken, userName, token); var result = reply.ReadCString(); switch (result) { case ReplyOk: var sessionId = reply.ReadCString(); var sessionCookie = GetCookie(); return(AuthResult.Success(sessionId, sessionCookie)); case ReplyNo: return(AuthResult.Fail()); default: throw new AuthException($"Unexpected reply {result} from auth server"); } }
private async Task <AuthResult> AuthActionAsync(LoginDto login) { var users = (await _userRepository.GetAllAsync(new UserByEmailSpec(login.Email))).ToArray(); if (users.Length != 1) { return(AuthResult.Fail()); } var targetUser = users[0]; if (!_hashService.Compare(targetUser, login.Password)) { return(AuthResult.Fail()); } var claims = _claimProvider.GetClaims(targetUser); return(AuthResult.Success(claims, _tokenFactory.Create(claims))); }
public AuthResult TryPassword(string userName, string password) { byte[] phash = Digest(password); var reply = Call(CmdTryPassword, userName, phash); var result = reply.ReadCString(); switch (result) { case ReplyOk: var sessionId = reply.ReadCString(); var sessionCookie = GetCookie(); return(AuthResult.Success(sessionId, sessionCookie)); case ReplyNo: var error = reply.ReadCString(); throw new AuthException(error); default: throw new AuthException($"Unexpected reply {result} from auth server"); } }