mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-06 14:40:28 -04:00
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:
parent
f12ba1502b
commit
22191ce648
591 changed files with 53264 additions and 3362 deletions
48
server/FSO.Server.Common/JsonWebToken/JWTokenFactory.cs
Executable file
48
server/FSO.Server.Common/JsonWebToken/JWTokenFactory.cs
Executable 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 };
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue