Exemplo n.º 1
0
        public Task <ObjectResult> Token([FromBody] RequestToken requestToken)
        {
            if (requestToken.User != "Itermediate2" || requestToken.Password != "Ct2JZAFqA59qL9G3")
            {
                return(new ResponseToken(false, "User or password is invalid").TaskResult());
            }

            var uniqueName   = requestToken.User;
            var createdDate  = DateTime.Now;
            var expiressDate = createdDate + TimeSpan.FromSeconds(_tokenConfigurations.Seconds);
            var token        = _jwtAuthService.GenerateToken(uniqueName, createdDate, expiressDate);

            return(new ResponseToken(true, null, createdDate.ToDateTimeEn(),
                                     expiressDate.ToDateTimeEn(), token).TaskResult());
        }
        async Task <bool> IsJwtTokenGenerated()
        {
            JWTContainer container = GetJwtContainer(_userName, Email);
            var          token     = _jwtAuthService.GenerateToken(container);

            if (!_jwtAuthService.IsTokenValid(token))
            {
                return(false);
            }
            else
            {
                var handler             = new JwtSecurityTokenHandler();
                var readToken           = handler.ReadToken(token);
                var tokenValidationTime = readToken.ValidTo;

                // for presisting the jwt token and its valid datetime.
                Application.Current.Properties[Constants.JwtToken]          = token;
                Application.Current.Properties[Constants.JwtTokenValidTime] = tokenValidationTime;
                await Application.Current.SavePropertiesAsync();

                return(true);
            }
        }