Endpoint authorization

Tokens are validated for some of the endpoints. Need to add other measures to rule out bogus tokens.
This commit is contained in:
Kun Deng
2022-08-26 18:01:29 -04:00
parent 2cc13ac9bb
commit d48716a54f
7 changed files with 221 additions and 12 deletions
+46
View File
@@ -0,0 +1,46 @@
using System;
using System.Linq;
using Newtonsoft.Json;
namespace Icarus.Models
{
public class Token
{
#region Properties
[JsonProperty("scope")]
public string Scope { get; set; }
[JsonProperty("exp")]
public int Expiration { get; set; }
[JsonProperty("aud")]
public string Audience { get; set; }
[JsonProperty("iss")]
public string Issuer { get; set; }
[JsonProperty("iat")]
public int Issued { get; set; }
#endregion
#region Methods
public bool TokenExpired()
{
var result = false;
var currentDate = DateTime.Now;
var currentDateInSeconds = Math.Floor((currentDate - DateTime.UnixEpoch).TotalSeconds);
result = (currentDateInSeconds >= Expiration) ? true : false;
return result;
}
public bool ContainsScope(string desiredScope)
{
var result = false;
result = Scope.Contains(desiredScope);
return result;
}
#endregion
}
}