Removed NioTSO client and server

- NioTSO client isn't needed because we're using RayLib
- Added FreeSO's API server to handle most backend operations
This commit is contained in:
Tony Bark 2024-05-01 02:55:43 -04:00
parent f12ba1502b
commit 22191ce648
591 changed files with 53264 additions and 3362 deletions

View file

@ -0,0 +1,48 @@
using FSO.Server.Common;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace FSO.Server.Servers.Api.JsonWebToken
{
public class JWTInstance
{
public string Token;
public int ExpiresIn;
}
public class JWTFactory
{
private JWTConfiguration Config;
public JWTFactory(JWTConfiguration config)
{
this.Config = config;
}
public JWTUser DecodeToken(string token)
{
var payload = JWT.JsonWebToken.Decode(token, Config.Key, true);
Dictionary<string, string> payloadParsed = JsonConvert.DeserializeObject<Dictionary<string, string>>(payload);
return Newtonsoft.Json.JsonConvert.DeserializeObject<JWTUser>(payloadParsed["data"]);
}
public JWTInstance CreateToken(JWTUser data)
{
var tokenData = Newtonsoft.Json.JsonConvert.SerializeObject(data);
return CreateToken(tokenData, Config.TokenDuration);
}
private JWTInstance CreateToken(string data, int expiresIn)
{
var expires = Epoch.Now + expiresIn;
var payload = new Dictionary<string, object>()
{
{ "exp", expires },
{ "data", data }
};
var token = JWT.JsonWebToken.Encode(payload, Config.Key, JWT.JwtHashAlgorithm.HS384);
return new JWTInstance { Token = token, ExpiresIn = expiresIn };
}
}
}