更改了授权Api

This commit is contained in:
CortexCore
2023-09-23 23:01:39 +08:00
parent c65fe87a6c
commit 6fab30a15c
5 changed files with 16 additions and 15 deletions

View File

@@ -77,17 +77,17 @@ public partial class LicenseService : EntityComponent,IAuthService
private HttpContent OnRequest(HttpListenerRequest arg)
{
var token = arg.RawUrl!.Split('/').Last();
//if (arg.HttpMethod is not "POST" or not "OPTIONS") return new StringContent(ContextModel.Error("Method Not Allowed"));
var sr = new StreamReader(arg.InputStream);
var token = sr.ReadToEnd();
AuthorizeAsync(token).Forget();
return new StringContent("success");
return new StringContent(ContextModel.Get(true));
}
public async UniTask AuthorizeAsync(string token)
{
var rawToken = token;
OnAuthorize?.Invoke(token);
token = JsonConvert.SerializeObject(token);
var response = await _httpClient.PostAsync(_requestAuthorizeUrl,new StringContent( token,Encoding.UTF8, "application/json"), _cancellationToken);
var response = await _httpClient.PostAsync(_requestAuthorizeUrl,new StringContent( JsonConvert.SerializeObject(token),Encoding.UTF8, "application/json"), _cancellationToken);
var message = await response.Content.ReadAsStringAsync(_cancellationToken);
if (response.IsSuccessStatusCode)
{
@@ -95,7 +95,7 @@ public partial class LicenseService : EntityComponent,IAuthService
BIT4Log.Log<IAuthService>($"授权成功:{message}");
var licenseBin = new LicenseBin
{
Token = rawToken,
Token = token,
ExpirationDate = DateTime.Now.AddDays(7)
};
PathHelper.EnsureDirectoryCreated(path);
@@ -105,7 +105,7 @@ public partial class LicenseService : EntityComponent,IAuthService
else
{
OnAuthorizeFailure?.Invoke(message);
BIT4Log.Log<IAuthService>($"当前Token:{rawToken}");
BIT4Log.Log<IAuthService>($"当前Token:{token}");
BIT4Log.Log<IAuthService>($"授权失败:{message}");
}
}