/// <summary> /// Function to generate unique token with expiry against the provided userId. /// Also add a record in database for generated token. /// </summary> /// <param name="userId"></param> /// <returns></returns> public TokenEntity GenerateToken(CustomerAPI userId) { string token = Guid.NewGuid().ToString(); DateTime issuedOn = DateTime.Now; DateTime expiredOn = DateTime.Now.AddSeconds(2154); // Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"])); var tokendomain = new TokenEntity { UserId = userId.EmailAddress, UserType = userId.UserType, AuthToken = token, IssuedOn = issuedOn, ExpiresOn = expiredOn }; userId.AuthData = new AuthenticationInfo(); userId.AuthData.Password = ""; userId.AuthData.AuthToken = token; userId.AuthData.IssuedOn = tokendomain.IssuedOn.ToLongTimeString(); userId.AuthData.ExpiresOn = tokendomain.ExpiresOn.ToLongTimeString(); // _dynamoDataService.UpdateItem(userId); // _dynamoDataService.UpdateMultipleAttributes(userId); _dynamoDataService.UpdateCustomerAuthItem(userId); var tokenModel = new TokenEntity() { UserId = userId.EmailAddress, UserType = userId.UserType, IssuedOn = issuedOn, ExpiresOn = expiredOn, AuthToken = token }; return(tokenModel); }