protected async Task <ITransitionResult> FinishFlowWithError(ITransitionInput input, ErrorType errorType, string message) { await _stopFlowCommand.ExecuteAsync(input.Context, message); return(CreateErrorResponse(input, errorType)); }
public async Task <ITransitionResult> HandleAsync(ITransitionInput input, CacheItem relatedItem) { try { BasicValidation(input, relatedItem); if (_validateSecurityTokens) { ValidateCacheItemTokens(relatedItem, input); } var castedInput = (TInput)input; Validate(castedInput, relatedItem); return(await ExecuteInternalAsync(castedInput, relatedItem)); } catch (OwnIdException e) { if (e.ShouldStopFlow) { return(await FinishFlowWithError(input, e.ErrorType, e.Message)); } return(CreateErrorResponse(input, e.ErrorType)); } }
private void BasicValidation(ITransitionInput input, CacheItem relatedItem) { if (input == null) { throw new ArgumentException($"{nameof(input)} param can not be null"); } if (relatedItem == null) { throw new ArgumentException($"{nameof(relatedItem)} param can not be null"); } if (!(input is TInput)) { throw new InternalLogicException($"Incorrect input type for {GetType().Name}"); } if (typeof(TInput) == typeof(JwtContainer)) { if (string.IsNullOrWhiteSpace((input as TransitionInput <JwtContainer>)?.Data?.Jwt)) { throw new CommandValidationException("JWT wasn't provided"); } } if (relatedItem.HasFinalState) { throw new CommandValidationException("Flow is already finished"); } }
// TODO: change return type public async Task <ITransitionResult> RunAsync(ITransitionInput input, StepType currentStep) { var item = await _cacheItemRepository.GetAsync(input.Context); input.IsDesktop = item.IsDesktop; return(await Flows[item.FlowType].RunAsync(input, currentStep, item)); }
public BaseJwtComposeInfo(ITransitionInput input) { Context = input.Context; ClientTime = input.ClientDate; Locale = input.CultureInfo?.Name; IsDesktop = input.IsDesktop; }
protected ITransitionResult CreateErrorResponse(ITransitionInput input, ErrorType errorType) { var composeInfo = new BaseJwtComposeInfo(input) { Behavior = FrontendBehavior.CreateError(errorType) }; var jwt = JwtComposer.GenerateFinalStepJwt(composeInfo); return(new JwtContainer(jwt)); }
private void ValidateCacheItemTokens(CacheItem item, ITransitionInput transitionInput) { if (item.RequestToken != transitionInput.RequestToken) { throw new CommandValidationException( $"{nameof(transitionInput.RequestToken)} doesn't match. Expected={item.RequestToken} Actual={transitionInput.RequestToken}"); } if (item.ResponseToken != transitionInput.ResponseToken) { throw new CommandValidationException( $"{nameof(transitionInput.ResponseToken)} doesn't match. Expected={item.ResponseToken} Actual={transitionInput.ResponseToken}"); } }