优化登出接口

This commit is contained in:
tongfei
2024-01-08 10:25:27 +08:00
parent 73c511ead8
commit 2596ac58ed
11 changed files with 228 additions and 112 deletions

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WMS.Web.Core.Dto.Login
{
public class LoginOutAuthorizeRequest
{
public string AccessToken { get; set; }
public string RefreshToken { get; set; }
}
}

View File

@@ -38,5 +38,7 @@ namespace WMS.Web.Core.Dto.Login
///ops自己产生的token 给前端验证用的
/// </summary>
public string Token { get; set; }
public string RefreshToken { get; set; }
}
}

View File

@@ -88,7 +88,7 @@ namespace WMS.Web.Core.Help
public string PostHttp(string url, LoginAuthorizeRequest reqData)
{
var str = string.Format("client_id={0}&client_secret={1}&grant_type={2}&username={3}&password={4}&scope={5}",
reqData.ClientId, reqData.ClientSecret, reqData.GrantType, reqData.UserName, reqData.Password,reqData.Scope);
reqData.ClientId, reqData.ClientSecret, reqData.GrantType, reqData.UserName, reqData.Password, reqData.Scope);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(str);
HttpContent httpContent = new StringContent(str);
@@ -111,13 +111,13 @@ namespace WMS.Web.Core.Help
var resData = response.Content.ReadAsStringAsync().Result;
return resData;
}
}
public string PostHttp(string url, LoginAuthorizeCodeRequest reqData)
{
var str = string.Format("client_id={0}&client_secret={1}&grant_type={2}&code={3}&scope={4}",
reqData.ClientId, reqData.ClientSecret, reqData.GrantType, reqData.Code,reqData.Scope);
reqData.ClientId, reqData.ClientSecret, reqData.GrantType, reqData.Code, reqData.Scope);
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byte1 = encoding.GetBytes(str);
HttpContent httpContent = new StringContent(str);
@@ -143,6 +143,37 @@ namespace WMS.Web.Core.Help
}
public string GetHttpOut(string url, LoginOutAuthorizeRequest reqData)
{
try
{
HttpClient client = new HttpClient();
//请求头添加其他值
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", reqData.AccessToken);
client.DefaultRequestHeaders.Add("Refresh-Authorization", reqData.RefreshToken);
client.DefaultRequestHeaders.Connection.Add("Keep-Alive");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.AcceptCharset.Add(new StringWithQualityHeaderValue ("utf-8"));
HttpResponseMessage response = client.GetAsync(url).Result;
if (response.IsSuccessStatusCode)
{
var resData = response.Content.ReadAsStringAsync().Result;
return resData;
}
else
{
var resData = response.Content.ReadAsStringAsync().Result;
return resData;
}
}
catch (Exception ex)
{
return "";
}
}
public string PostHttpNoData(string url, string cookieValue = "")
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);