Implement password based authorization.

This commit is contained in:
2025-02-23 18:07:43 -05:00
parent 99f7061a9f
commit 0e9e110e01
6 changed files with 24 additions and 24 deletions

View File

@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MarketData.Service
{

View File

@@ -42,7 +42,7 @@ namespace MarketData.Service
/// </summary>
/// <param name="url">The fully qualified url http://100.0.0.0:8000.</param>
/// <param name="user">The user.</param>
public void SetUrl(String url,String user)
public void SetUrl(String url,String user, String password)
{
lock(this)
{
@@ -51,7 +51,7 @@ namespace MarketData.Service
httpClient = new HttpClient();
httpClient.BaseAddress = baseUri;
httpClient.Timeout=CONNECTION_TIMEOUT;
ServiceResult serviceResult=Login(user);
ServiceResult serviceResult=Login(user, password);
if(!serviceResult.Success)return;
accessToken=(String)serviceResult.ContextSpecificResult;
}
@@ -97,7 +97,7 @@ namespace MarketData.Service
}
}
}
private ServiceResult Login(String user)
private ServiceResult Login(String user, String password)
{
lock(this)
{
@@ -106,7 +106,9 @@ namespace MarketData.Service
if(!IsNetworkAvailable())return new ServiceResult(false,"No network.");
StringBuilder sb = new StringBuilder();
user = Authorizations.Xor(user);
password = Authorizations.Xor(password);
sb.Append("/api/Authorization/GetToken?").Append("user=").Append(user);
sb.Append("&password=").Append(password);
String json = httpClient.GetStringAsync(sb.ToString()).Result;
String accessToken = JsonConvert.DeserializeObject<String>(json);
return new ServiceResult(accessToken);