/// <summary> /// 获取解密后token /// <param name="token">token</param> /// <returns>解密后token<</returns> public static string GetToken(string token) { if (string.IsNullOrEmpty(token)) { return(token); } return(ScryptHelper.DecryptDES(Microsoft.JScript.GlobalObject.decodeURIComponent(token))); }
public JsonResult RefreshToken(OAuth2Result model) { try { // 删除日志 HangfireHelper.StartHanfireWork(); var clientId = model.ClientId; var clientSecret = model.ClientSecret; var refreshToken = ScryptHelper.DecryptDES(model.RefreshToken); var basic = Convert.ToBase64String(Encoding.Default.GetBytes($"{clientId}:{clientSecret}")); string resStr = string.Empty; var handler = new WebRequestHandler(); handler.ServerCertificateValidationCallback = delegate { return(true); }; using (var httpClient = new HttpClient(handler)) { httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + basic); var json = $"grant_type=refresh_token&refresh_token={refreshToken}"; var content = new StringContent(json, Encoding.UTF8, "application/x-www-form-urlencoded"); var res = httpClient.PostAsync($"{Constant.OAuth2Url}/oauth2/token", content).Result; resStr = res.Content.ReadAsStringAsync().Result; _log.Debug($"RefreshToken oauth2 token: '{resStr}'"); } var obj = JsonConvert.DeserializeObject <dynamic>(resStr); OAuth2Result result = new OAuth2Result() { AccessToken = ScryptHelper.EncryptDES($"Bearer {obj["access_token"].Value}"), ExpireIn = DateTime.Now.AddSeconds(obj["expires_in"].Value), IdToken = obj["id_token"].Value, RefreshToken = ScryptHelper.EncryptDES(obj["refresh_token"].Value), ClientId = model.ClientId, ClientSecret = model.ClientSecret }; return(Json(new { success = true, token = JsonConvert.SerializeObject(result) })); } catch (Exception ex) { _log.Debug($"RefreshToken Parameter: {JsonConvert.SerializeObject(model)}, Exception: {ex.Message}"); return(Json(new { success = false })); } }