public IActionResult GetCharacters() { // Check if token is in session string token = HttpContext.Session.GetString("token"); if (string.IsNullOrWhiteSpace(token) || !WowApiHelper.CheckTokenExpiry(HttpContext.Session.GetString("expiry"))) { return(Redirect(Url.Content("~/"))); } var client = new RestClient($"{BASE_API_URL}/profile/user/wow?locale=en_US&namespace=profile-us"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Authorization", $"Bearer {token}"); IRestResponse response = client.Execute(request); WowProfile profileResponse = JsonConvert.DeserializeObject <WowProfile>(response.Content); return(Ok(profileResponse)); }
public IActionResult RedeemCoded(string code) { // Check Token Expiry - return OK if we have a valid token in user session if (!string.IsNullOrWhiteSpace(HttpContext.Session.GetString("token")) && WowApiHelper.CheckTokenExpiry(HttpContext.Session.GetString("expiry"))) { return(Ok("Valid token exists.")); } // Continue to get new Token if Token is Null or Expired WowAccessToken tokenResponse = GetToken(code); if (!string.IsNullOrWhiteSpace(tokenResponse.AccessToken) && string.IsNullOrWhiteSpace(tokenResponse.Error)) { tokenResponse.SetTokenExpiryTime(); // Set Session Storage of User Token / Expiry HttpContext.Session.SetString("token", tokenResponse.AccessToken); HttpContext.Session.SetString("expiry", tokenResponse.ExpiryTime.ToString()); return(Ok("Token granted.")); } else { return(StatusCode(StatusCodes.Status500InternalServerError, tokenResponse)); } }