Пример #1
0
        public async Task <CreateTokenResponse> Handle(CreateTokenRequest request, CancellationToken cancellationToken)
        {
            var generatedString = _randomStringGenerator
                                  .GenerateString(CharacterType.Lowercase | CharacterType.Uppercase | CharacterType.Numerics, 64);

            var requestToken = new Domains.Dto.RequestToken {
                Key     = generatedString,
                Expires = _clockProvider.DateTimeOffset
                          .AddMinutes(request.ValidityPeriodInMinutes)
            };

            var savedRequestToken = await _requestTokenService.SaveRequestToken(await _encryptionProvider
                                                                                .Encrypt <Domains.Dto.RequestToken, RequestToken>(requestToken), cancellationToken);

            return(Response.Success <CreateTokenResponse>(await _encryptionProvider
                                                          .Decrypt <RequestToken, Domains.Dto.RequestToken>(savedRequestToken)));
        }
        public async Task <ValidateTokenResponse> Handle(ValidateTokenRequest request, CancellationToken cancellationToken)
        {
            var requestToken = new RequestToken {
                Key = request.Token
            };

            var encryptedToken = await _encryptionProvider.Encrypt <RequestToken, Domains.Data.RequestToken>(requestToken);

            encryptedToken = await _requestTokenService.GetRequestToken(encryptedToken.Key, cancellationToken);

            encryptedToken.Expires = _clockProvider.DateTimeOffset;

            await _requestTokenService.SaveRequestToken(encryptedToken, cancellationToken);

            return(new ValidateTokenResponse {
                IsSuccessful = true
            });
        }