public override async Task <RegisterResponse> Register(RegisterRequest request, ServerCallContext context) { _logger.LogInformation($"Registration request: {request.ToJson()}"); var token = await _registrationTokenService.GetByOriginalTokenAsync(request.Token); if (token == null || token.ExpirationDate <= DateTime.UtcNow || !token.EmailVerified || !token.PhoneVerified || token.EmailHash != request.Email.ToSha256().ToBase64() || token.PhoneHash != request.Phone.ToSha256().ToBase64()) { context.Status = new Status(StatusCode.Unauthenticated, "Unauthorized"); return(new RegisterResponse() { Error = new ErrorV1() { Code = ErrorModelCode.NotAuthenticated.ToString(), Message = ErrorMessages.Unauthorized } }); } if (!ValidatePublicKey(request.PublicKey)) { return(new RegisterResponse() { Error = new ErrorV1() { Code = ErrorModelCode.InvalidInputField.ToString(), Message = ErrorMessages.InvalidFieldValue(nameof(request.PublicKey)) } }); } if (!token.RegistrationDone) { var registrationResult = await _accountManager.RegisterAccountAsync( "demo", request.Email, request.Phone, request.FullName, request.CountryIso3Code, request.AffiliateCode, request.Password, request.Hint, request.Pin); if (registrationResult == null) { return(new RegisterResponse() { Error = new ErrorV1() { Code = ErrorModelCode.RuntimeProblem.ToString(), Message = ErrorMessages.RuntimeProblemTryAgain } }); } if (registrationResult.IsEmailAlreadyExist || registrationResult.IsClientAlreadyExist) { return(new RegisterResponse() { Error = new ErrorV1() { Code = ErrorModelCode.ClientAlreadyExist.ToString(), Message = ErrorMessages.ClientAlreadyExist } }); } token.LastCodeHash = string.Empty; token.ClientId = registrationResult.ClientIdentity.ClientId; token.TenantId = registrationResult.ClientIdentity.TenantId; token.RegistrationDone = true; await _registrationTokenService.SaveAsync(token); } var(_, sessionToken) = await _sessionService.CreateVerifiedSessionAsync(token.TenantId, token.ClientId, request.PublicKey); return(new RegisterResponse() { Result = new RegisterResponse.Types.RegisterPayload() { SessionId = sessionToken, CanCashInViaBankCard = false, NotificationsId = string.Empty, //todo: set notification id SwiftDepositEnabled = false, State = "OK", PersonalData = new Swisschain.Lykke.AntaresWalletApi.ApiContract.PersonalData() { Phone = request.Phone, Email = request.Email } } }); }