/// <summary> /// get token for user when valid /// </summary> /// <returns>returns valid token for user with view claims</returns> public Outcome Execute() { var response = new Outcome(); if (responseDTO.Data.Type == "Enable") { CreateJWT createJWT = new CreateJWT(); string token = createJWT.CreateToken(responseDTO.Data.UserName); ConvertToJWT convertToJWT = new ConvertToJWT(token); response.Result = new LoginResponseDTO() { token = token, username = responseDTO.Data.UserName, viewclaims = convertToJWT.GetClaimsFromToken(), Messages = new List <string>(), isSuccessful = true }; } else { response.Result = new LoginResponseDTO() { Messages = new List <string>(), isSuccessful = false }; } return(response); }
/// <summary> /// refreshes token /// </summary> /// <returns>new token</returns> public TokenRefreshResponseDTO RefreshService() { LoginGateway gateway = new LoginGateway(); LoginDTO incUsername = new LoginDTO() { UserName = username, Token = response.token }; response.Messages = new List <string>(); var storetoken = gateway.AddTokenToBlackList(incUsername); if (storetoken.isSuccessful == false) { response.Messages.Add("Failed to add token"); return(response); } CreateJWT newJWT = new CreateJWT(); var jwt = newJWT.CreateToken(username); if (jwt == "Failed") { response.Messages.Add("Failed To make token"); return(response); } response.token = jwt; response.username = this.username; response.isSuccessful = true; response.Messages.Add("Success!"); return(response); }