Token validation
This commit is contained in:
@@ -128,7 +128,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
var result = false;
|
var result = false;
|
||||||
var token = DecodeToken(accessToken);
|
var token = DecodeToken(accessToken);
|
||||||
|
|
||||||
if (token == null)
|
if (token == null || token.Erroneous())
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -148,6 +148,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
var rsaParams = GetRSAPublic(_publicKey);
|
var rsaParams = GetRSAPublic(_publicKey);
|
||||||
Token tok = null;
|
Token tok = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
using (var rsa = new RSACryptoServiceProvider())
|
using (var rsa = new RSACryptoServiceProvider())
|
||||||
{
|
{
|
||||||
rsa.ImportParameters(rsaParams);
|
rsa.ImportParameters(rsaParams);
|
||||||
@@ -162,6 +164,11 @@ namespace Icarus.Controllers.Managers
|
|||||||
var json = decoder.Decode(accessToken);
|
var json = decoder.Decode(accessToken);
|
||||||
tok = JsonConvert.DeserializeObject<Token>(json);
|
tok = JsonConvert.DeserializeObject<Token>(json);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error("An error occurred: {0}", ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return tok;
|
return tok;
|
||||||
|
|||||||
@@ -41,6 +41,16 @@ namespace Icarus.Models
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Erroneous()
|
||||||
|
{
|
||||||
|
var result = true;
|
||||||
|
Func<string, bool> isEmpty = a => string.IsNullOrEmpty(a);
|
||||||
|
result = (!isEmpty(Scope) && !isEmpty(Audience) && !isEmpty(Issuer) &&
|
||||||
|
Expiration > 0 && Issued > 0) ? false : true;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user