mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-22 02:12:22 +00:00
Make token validation on each request (auth provider should take care for caching)
This commit is contained in:
parent
400c5410e9
commit
4dc832856e
@ -4,7 +4,6 @@ namespace Zirconium.Core.Models
|
|||||||
{
|
{
|
||||||
public class Session
|
public class Session
|
||||||
{
|
{
|
||||||
public string LastTokenHash { get; set; }
|
|
||||||
public SessionAuthData LastTokenPayload { get; set; }
|
public SessionAuthData LastTokenPayload { get; set; }
|
||||||
public IPAddress ClientAddress { get; set; }
|
public IPAddress ClientAddress { get; set; }
|
||||||
public ConnectionHandler ConnectionHandler { get; set; }
|
public ConnectionHandler ConnectionHandler { get; set; }
|
||||||
|
@ -45,37 +45,28 @@ namespace Zirconium.Core
|
|||||||
{
|
{
|
||||||
if (h.IsAuthorizationRequired())
|
if (h.IsAuthorizationRequired())
|
||||||
{
|
{
|
||||||
string hash;
|
SessionAuthData tokenPayload;
|
||||||
using (SHA512 shaM = new SHA512Managed())
|
try
|
||||||
{
|
{
|
||||||
hash = shaM.ComputeHash(message.AuthToken.ToByteArray()).ConvertToString();
|
tokenPayload = _app.AuthManager.ValidateToken(message.AuthToken);
|
||||||
}
|
}
|
||||||
if (session.LastTokenHash != hash)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
SessionAuthData tokenPayload;
|
Log.Warning(e.Message);
|
||||||
try
|
var errorMsg = OtherUtils.GenerateProtocolError(
|
||||||
{
|
message,
|
||||||
tokenPayload = _app.AuthManager.ValidateToken(message.AuthToken);
|
"unauthorized",
|
||||||
}
|
"Unauthorized access",
|
||||||
catch (Exception e)
|
new Dictionary<string, object>()
|
||||||
{
|
);
|
||||||
Log.Warning(e.Message);
|
errorMsg.From = _app.Config.ServerID;
|
||||||
var errorMsg = OtherUtils.GenerateProtocolError(
|
var serializedMsg = JsonConvert.SerializeObject(errorMsg);
|
||||||
message,
|
|
||||||
"unauthorized",
|
|
||||||
"Unauthorized access",
|
|
||||||
new Dictionary<string, object>()
|
|
||||||
);
|
|
||||||
errorMsg.From = _app.Config.ServerID;
|
|
||||||
var serializedMsg = JsonConvert.SerializeObject(errorMsg);
|
|
||||||
|
|
||||||
session.ConnectionHandler.SendMessage(serializedMsg);
|
session.LastTokenPayload = null;
|
||||||
return;
|
session.ConnectionHandler.SendMessage(serializedMsg);
|
||||||
}
|
return;
|
||||||
|
|
||||||
session.LastTokenHash = hash;
|
|
||||||
session.LastTokenPayload = tokenPayload;
|
|
||||||
}
|
}
|
||||||
|
session.LastTokenPayload = tokenPayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
var task = Task.Run(() =>
|
var task = Task.Run(() =>
|
||||||
@ -85,9 +76,12 @@ namespace Zirconium.Core
|
|||||||
});
|
});
|
||||||
handlerTasks.Add(task);
|
handlerTasks.Add(task);
|
||||||
}
|
}
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
Task.WaitAll(handlerTasks.ToArray());
|
Task.WaitAll(handlerTasks.ToArray());
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
Log.Error(e.ToString());
|
Log.Error(e.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user